Skip to content

Invalid emit for class+namespace using module=commonJs in TS 3.9 #37118

Description

@mjbvz

TypeScript Version: 3.9.0-dev.20200228

Search Terms:

  • export
  • namespace

Code
With target = ES2017, module = commonJS

export class Color {
    static readonly x = new Color();
}

export namespace Color {
    export const a = 1
}

Expected behavior:
In TS 3.8, this emits:

Object.defineProperty(exports, "__esModule", { value: true });
class Color {
}
exports.Color = Color;
Color.x = new Color();
(function (Color) {
    Color.a = 1;
})(Color = exports.Color || (exports.Color = {}));

Actual behavior:
In TS 3.9, this emits:

Object.defineProperty(exports, "__esModule", { value: true });
const Color = /** @class */ (() => {
    class Color {
    }
    Color.x = new Color();
    return Color;
})();
exports.Color = Color;
(function (Color) {
    Color.a = 1;
})(Color = exports.Color || (exports.Color = {}));
exports.Color = Color;

Which is not valid since it tries to reassign a constant value: Color = exports.Color

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions