microsoft / microsoft/TypeScript
Infer constrained generic parameters after instanceof check
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
TypeScript Version: 2.4.0
When a variable passes an instanceof check generic type with constraints on the type parameter, apply to constraints to the variable. There is currently no clean way to handle the following without an explicit cast:
Code
interface Foo {
foo: string;
}
class Bar<T extends Foo> {
constructor(readonly bar: T) {}
}
let a: any;
if (a instanceof Bar) {
a.bar; // <-- a.bar should be 'Foo' instead of 'any'
}
Expected behavior:
a.bar is inferred as an instance of Foo.
Actual behavior:
a.bar is any
This change would only impact type checking, and will not affect compilation output.
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 der TypeScript-Reproduktion im Issue und untersuche, wie die instanceof-Prüfung eine Variable eingrenzt, deren generischer Typparameter eine Constraint hat. Überprüfe den inferierten Typ von a.bar und identifiziere den relevanten Bereich für Type-Checking-Tests. Als abgeschlossen gilt die Aufgabe, wenn a.bar als Foo inferiert wird, ohne die Kompilierungsausgabe zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100