microsoft / microsoft/TypeScript

Missing constraint error in instantiation expression for a nested class

オープン
#61,982 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: check: Variance Relationships Help Wanted
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
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`)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた TypeScript Playground の再現コードから始め、checkTypeArguments、structuredTypeRelatedToWorker、そして inVarianceComputation パスを通って getInstantiatedSignatures を追跡してください。5.6 の Playground リンクと動作を比較し、遅延されたチェックまたはキャッシュされていないチェックで制約エラーをどのように報告すべきかを判断してください。現在の再現コードが診断 2344 を生成し、関連する型チェックの動作を壊さなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。