microsoft / microsoft/TypeScript
Error not generated for nested generic array
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
error, nested, array, order
🕗 Version & Regression Information
- This changed between versions 4.4.4 and 4.5.5 (from playground testing - all later version exhibit this behaviour).
⏯ Playground Link
💻 Code
type TypeA = number;
type TypeB = boolean;
type DataTypeTwo<T extends TypeA | TypeB> = {
one: Array<{ two: Array<T> }>;
};
type DataTypeThree<T extends TypeA | TypeB> = {
one: Array<{ two: Array<{ three: Array<T> }> }>;
};
let testingThreeErr: DataTypeThree<TypeA> = {
one: [{ two: [ {three: [ true ] } ]}] // errors as expected
};
let testingTwoErr: DataTypeTwo<TypeA> = {
one: [{ two: [ false ] }] // errors as expected
};
// Uncomment these lines to see all errors
// let testingTwoPre: DataTypeTwo<TypeA> = {
// one: [{ two: [ 5 ] }]
// };
// let t2aPre: DataTypeTwo<TypeB> = testingTwoPre;
let testingThree: DataTypeThree<TypeA> = {
one: [{ two: [ {three: [ 5 ] } ]}]
};
// Comment out this line to see error for t2a assignment
let t3a: DataTypeThree<TypeB> = testingThree; // Should error, but does not
let testingTwo: DataTypeTwo<TypeA> = {
one: [{ two: [ 5 ] }]
};
let t2a: DataTypeTwo<TypeB> = testingTwo; // errors only if section above commented out
let check: number = "asdf"; // always errors, as it should
// Comment out L27 to see correct error on L32
// Uncomment L27 and lines 18-21 to see all errors correctly
// Works as expected in v4.4.4, but not any later versions
🙁 Actual behavior
No errors on lines 27 and 32 (assigning an incompatible type).
🙂 Expected behavior
Should error on those lines.
Additional information about the issue
The code works (i.e. gives correct errors) in version 4.4.4 (pg).
I assume this is to with depth limits, as it works fine for the two level case (DataTypeTwo) - though if the bad assignment comes after the three level case then even this error is not shown. (i.e. need to comment out line 27 in the example for the bad assignment to the DataTypeTwo variable to correctly error).
Even more oddly, if a bad assignment to a DataTypeTwo variable is made before the bad assignment to a DataTypeThree, the DataTypeThree assignment begins to error correctly. (Uncomment lines 18-21 in the example).
Possibly related to #56291.
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 verlinkten TypeScript Playground und vergleiche die Reproduktion in 4.4.4 mit 5.6.3 oder höher. Untersuche anhand der Beispiele und des verwandten issue #56291, warum die verschachtelten Zuweisungen von DataTypeTwo und DataTypeThree beeinflussen, ob inkompatible Zuweisungen gemeldet werden. Als erledigt gilt die Aufgabe, wenn die Zuweisungen in den Zeilen 27 und 32 zuverlässig Fehler erzeugen, ohne von der Reihenfolge des Codes abzuhängen, und eine Regressionstestabdeckung in den Compiler-Tests hinzugefügt wurde.
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
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100