microsoft / microsoft/TypeScript

Uncomputed generic type does not follow structural typing

Aperta
#52,096 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 26/6/2023.

Bug Domain: check: Variance Relationships Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

🔎 Search Terms

generic
unassignable type
uncomputed type

🕗 Version & Regression Information
⏯ 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_TB is false.
  • a is not assignable to b.
🙂 Expected behavior
  • All types TA_extends_TB should be true, the same way as C_extends_D and PickA_extends_PickB.
  • a should be assignable to b and vice-versa, the same way as c and d.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.