Skip to content

namespaces don't respect constsΒ #61568

@pushkine

Description

@pushkine

πŸ”Ž Search Terms

namespace const generated

πŸ•— Version & Regression Information

ts stable & nightly

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.3#code/KYDwDg9gTgLgBAOwIYFtgGcxIMbDgMQgjgG8AoOSuUSWObCBdeAMyLgF5SBfAbgqo1orAK4JsMAJaM4AIyRQAFAEpScKMBgioCOGwi843MtyA

πŸ’» Code

export namespace Foo {
    export const foo = {};
    export function bar() { return foo; }
}

πŸ™ Actual behavior

export var Foo;
(function (Foo) {
    Foo.foo = {};
    function bar() { return Foo.foo; }
    Foo.bar = bar;
})(Foo || (Foo = {}));

const <name> is not generated, and typecript injects property accessors <namespace>.<name>

πŸ™‚ Expected behavior

export var Foo;
(function (Foo) {
    const foo = {};
    Foo.foo = foo;
    function bar() { return foo; }
    Foo.bar = bar;
})(Foo || (Foo = {}));

const <name> is generated, and typescript does not inject property accessors

Additional information about the issue

I'd expect export let/var <name> variables to work this way since they can be modified, but consts should be declared as consts in the codegen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions