microsoft / microsoft/TypeScript

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

Open
#61,944 1 comment 2 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Bug Domain: Declaration Emit Help Wanted
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.