microsoft / microsoft/TypeScript

Uncomputed generic type does not follow structural typing

Open
#52,096 1 comment 0 reactions 1 assignee View on GitHub

@weswigham is already working on this.

Since Jun 26, 2023.

Bug Domain: check: Variance Relationships Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.