microsoft / microsoft/TypeScript
Missing constraint error in instantiation expression for a nested class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
### 🔎 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`)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften TypeScript Playground-Repro und verfolge getInstantiatedSignatures durch checkTypeArguments, structuredTypeRelatedToWorker und den inVarianceComputation-Pfad. Vergleiche das Verhalten mit dem 5.6 Playground-Link und bestimme, wie die verzögerte oder nicht zwischengespeicherte Prüfung den Constraint-Fehler melden sollte. Als erledigt gilt die Aufgabe, wenn das aktuelle Repro die Diagnose 2344 erzeugt, ohne verwandtes Type-Checking-Verhalten zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100