Skip to content

Uncomputed generic type does not follow structural typing #52096

Open
@quangloc99

Description

@quangloc99

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions