microsoft / microsoft/TypeScript
Incorrect type declarations for a constant inside a namespace merged with an enum
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 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
```ts
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)
```ts
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
```ts
declare enum Foo {
bar = 0
}
declare namespace Foo {
const baz = Foo.bar;
}
```
or
```ts
declare enum Foo {
bar = 0
}
declare namespace Foo {
const baz: Foo;
}
```
### Additional information about the issue
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.