Skip to content

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

Closed

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

  1. changed the title [-]Invalid emit for module: commonJs in TS 3.9[/-] [+]Invalid emit for class+namespace using module=commonJs in TS 3.9[/+] on Feb 28, 2020
  2. mjbvz commented on Feb 28, 2020

    @mjbvz
    ContributorAuthor

    /cc Ryan Cavanaugh (@RyanCavanaugh) This blocks using TS 3.9 for building VS Code

  3. mjbvz commented on Feb 28, 2020

    @mjbvz
    ContributorAuthor

    Ron Buckton (@rbuckton) Possibly introduced by #36795

  4. weswigham commented on Feb 28, 2020

    @weswigham
    Member

    Ack, this is probably my fault - as a follow up to the community PR, I updated it to use const, thinking it was more desirable - I didn't realize we relied on the ability to reassign the class declaration later on (even if we're reassigning it to itself in most cases). Regressed by #36907.

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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