microsoft / microsoft/TypeScript
Uncomputed generic type does not follow structural typing
Offen
@weswigham arbeitet bereits daran.
Seit 26.6.2023.
Bug
Domain: check: Variance Relationships
Rescheduled
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
🔎 Search Terms
generic
unassignable type
uncomputed type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about:
⏯ Playground Link
Playground link with relevant code
💻 Code
class A {
x: string = 'A';
y: number = 0;
}
class B {
x: string = 'B';
z: boolean = true;
}
type T<X extends { x: any }> = Pick<X, 'x'>;
type C = T<A>;
type D = T<B>;
type C_extends_D = C extends D ? true : false; // true
type PickA_extends_PickB = Pick<A, 'x'> extends Pick<B, 'x'> ? true : false; // true
type TA_extends_TB = T<A> extends T<B> ? true : false; // false (?)
declare let a: T<A>;
declare let b: T<B>;
declare let c: C;
declare let d: D;
b = a; // error here (?)
c = d;
🙁 Actual behavior
- Type
TA_extends_TBisfalse. ais not assignable tob.
🙂 Expected behavior
- All types
TA_extends_TBshould betrue, the same way asC_extends_DandPickA_extends_PickB. ashould be assignable toband vice-versa, the same way ascandd.
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.
Bewertung
Dieses Issue wurde noch nicht bewertet.