microsoft / microsoft/TypeScript

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

Đang mở
#61,944 1 bình luận 2 reaction 1 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Domain: Declaration Emit Help Wanted
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

### 🔎 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_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.