microsoft / microsoft/TypeScript
Incorrect type resolution with nested constructors
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
nested constructors type resolution anti-pattern
### 🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because I only report bugs to be helpful, but I don't have time to dive deeper myself.
### ⏯ Playground Link
https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAE2AYwDYEMrDsiA7AZ3gCF0DgAuOAbwCgBIPYAdwAoBKKu++gawEs8CKgHIAgiIaMWHLnAFDRxEXAC+DdetyF4YuAF44TZjgwECcUDGBCLpcjTW1tROMQNGWpshas2EFnrUTsQAdAoIQA
### 💻 Code
```ts
export declare const Base: {
new(): {
kind: 'A'
new(): { kind: 'B' }
}
}
const A = new class extends Base { }
const B = new class extends A { }
B.kind // shows 'A', but should be 'B'
```
### 🙁 Actual behavior
If a ctor returns another ctor, it repeats the first level. In the above example, B.kind is 'A', but since we extended and instantiated twice, it should be 'B'.
### 🙂 Expected behavior
After extending twice, it should reach the inner class, instead of repeating the outer one.
### Additional information about the issue
I can only reproduce this bug with this weird experimental anti-pattern - so on its own probably not a priority at all, but types should probably reflect the runtime state as much as possible, even in weird edge cases such as this, and it might indicate a deeper underlying issue.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 复现开始,跟踪两个嵌套的 `new class extends ...` 表达式的类型解析过程。在两次扩展和实例化之后,当示例将 `B.kind` 报告为 `'B'` 而不是 `'A'` 时,工作就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100