microsoft / microsoft/TypeScript
Missing constraint error in instantiation expression for a nested class
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
instantiation expression caching class expression declaration type arguments type parameter
### 🕗 Version & Regression Information
- This changed in PR: https://github.com/microsoft/TypeScript/pull/59931 , cc @weswigham
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250701#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AJLoIAFzDpg+RAE8ADvnhSV+APYAzOADoAQvASJi5jtAD0V6FIEwIvLZmHQihLYQrdpYKfzA0IaoPOBQwUjuAB5S+OhCMLChsKSU1NTKYITxUqKc3AC+XIUUQA
### 💻 Code
```ts
class A {
value!: T;
child!: InstanceType>>; // this should error
static B = class B {
parent!: T;
};
}
```
### 🙁 Actual behavior
It doesn't error
### 🙂 Expected behavior
it should error with:
```
Type 'A' does not satisfy the constraint 'A'.
Type 'T' is not assignable to type 'number'.(2344)
```
like it did in 5.6: [TS playground](https://www.typescriptlang.org/play/?ts=5.6.3#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AJLoIAFzDpg+RAE8ADvnhSV+APYAzOADoAQvASJi5jtAD0V6FIEwIvLZmHQihLYQrdpYKfzA0IaoPOBQwUjuAB5S+OhCMLChsKSU1NTKYITxUqKc3AC+XIUUQA)
### Additional information about the issue
The problem here is that the situation is a little bit circular and variances worker gets hits in reentrant manner. The nested call returns `emptyArray` that is a signal for `structuredTypeRelatedToWorker` to return `Ternary.Unknown`.
So `checkTypeArguments` called by `getInstantiatedSignatures` doesn't report an error. In the old version of the code, this would be re-called after the variance worker would completely exit and the error would be raised.
I see 2 ways to solve this:
- ignore the introduced caching based `inVarianceComputation` to avoid spoiling this
- defer `checkTypeArguments` in `getInstantiatedSignatures` (well, call it with `/*reportErrors*/ false` and defer anoher call with `/*reportErrors*/ true`)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 复现开始,跟踪 getInstantiatedSignatures 经由 checkTypeArguments、structuredTypeRelatedToWorker 以及 inVarianceComputation 路径的执行过程。将其行为与 5.6 Playground 链接进行比较,并确定延迟检查或未缓存的检查应如何报告约束错误。当当前复现产生诊断 2344,且不破坏相关的类型检查行为时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100