Microsoft/TypeScript

Incorrect type declarations for a constant inside a namespace merged with an enum

Open

#61,944 建立於 2025年6月25日

在 GitHub 查看
 (1 留言) (2 反應) (1 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitFix AvailableHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 Search Terms

"enum", "namespace", "declaration", "d.ts", "const"

🕗 Version & Regression Information

  • This changed between versions 3.1.0-dev.20180906 and 3.1.0-dev.20180907

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYOwrgtgBAYg9nKBvAUFdUBGBDATigXxRGwmAGcAHbAY2FgWTQ2AA9K5cAXKGuEcjxwAvKAF4GcAHQ5cAbkIogA

💻 Code

enum Foo {
    bar
}
namespace Foo {
    export const baz = Foo.bar;
}

🙁 Actual behavior

Typescript generates invalid d.ts for the enum value assigned to the constant (in all versions starting 3.1.0-dev.20180907)

declare enum Foo {
    bar = 0
}
declare namespace Foo {
    const baz = bar; // <-- unknown `bar` identifier, `baz` type is `any`
}

In versions before 3.1.0-dev.20180906 the constant is declared as const baz: Foo;

🙂 Expected behavior

Typescript generates a valid declaration of the constant

declare enum Foo {
    bar = 0
}
declare namespace Foo {
    const baz = Foo.bar;
}

or

declare enum Foo {
    bar = 0
}
declare namespace Foo {
    const baz: Foo;
}

Additional information about the issue

No response

貢獻者指南