Skip to content

failed to check the equality between two union type if union type has over 20 type #47077

Closed
@Sczlog

Description

@Sczlog

Bug Report

if there is an union type contains over 20 type, it will failed to assign the data to its property with the same type, even by itself.

🔎 Search Terms

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.5.2
    and I also check next and nightly version, the bug still exist

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.6.0-dev.20211208#code/C4TwDgpgBAglC8UDeVSQFxQEQy1AvgNwBQa0AQgsquBJluXkabVAMJUpn1tMllQAIpxoZsgvi0hQAoiO7YZkgQDF5teiuWsA4urFYd26QAl9dbCePQAkufo3rUAFL3szpwGk3WT04AyPv5OALI+IU4Acj6RTgDyPnFOAAo+yU4Aij4ZTgBKPrlOAMo+RU4AKj7lTgCqPjVOAGo+jU4A6j5tTgAaPt1OAJo+A04AWj6jklLQMACMPrgE-Kzk84hcGtiMS9Psa9QKWLw7AoL7GwYSJ6wy56IWWErX0ip3h1rP0Dpvm4ZOJj8DFZPlAbICHo4Qc5wfQPCDPDDsH4Qf5EVhgiCQmiIiDImjYiC4mikiDkmj0iCMmiciDcmjCiCimiyiDymjqiCamiGiDGmjWiC2miuiDumj+iCBmiRiDRmjJjtdgBXAB2AEsAPYqhDEKB6qAAH1guv1RvIJr1RrYFsNQhtRpk9qgKidOidJidNidzidnid-idISdkSdcSdySdGSduSdRSd5SdNSdjSdbSd3SdAydoxIyvVWrWTrmTtWTrYsydZydtydr1dFf1toBnobppcrctUAR-o7tqxwd7RqJ4cHUCp0dHTPjo65ydHQvTo6l2dmuYAxlqAM7AKAAMw1GqoAAoAB6YVWalWzACU5-z2vgAD5kDaAE4QYBK1-apA2xsKE8ADoyAAGhtZhmGIDcVW3KAACMAENX2PM8oAvAtbzQ+8EGfX9G3fT9vygE8SEg6DYJPEAAC9j0w9CH1wt8Py-H8-31Q5cDAxsINzARNwAC1fNUVQAaxqbDEDgM1bQ4I1BGWaQBKE0TxMvfY5ltVYZPmOTV2IKCtx3fcNX2U9MCU4SxPvG9zMEyzVK1HCX3w5iiLwxt2M2IDQPA0iSCAA

💻 Code

type A = { type: "A" };
type B = { type: "B" };
type C = { type: "C" };
type D = { type: "D" };
type E = { type: "E" };
type F = { type: "F" };
type G = { type: "G" };
type H = { type: "H" };
type I = { type: "I" };
type J = { type: "J" };
type K = { type: "K" };
type L = { type: "L" };
type M = { type: "M" };
type N = { type: "N" };
type O = { type: "O" };
type P = { type: "P" };
type Q = { type: "Q" };
type R = { type: "R" };
type S = { type: "S" };
type T = { type: "T" };
type U = { type: "U" };
type V = { type: "V" };
type W = { type: "W" };
type X = { type: "X" };
type Y = { type: "Y" };
type Z = { type: "Z" };

type A1 = { type: "A" };
type B1 = { type: "B" };
type C1 = { type: "C" };
type D1 = { type: "D" };
type E1 = { type: "E" };
type F1 = { type: "F" };
type G1 = { type: "G" };
type H1 = { type: "H" };
type I1 = { type: "I" };
type J1 = { type: "J" };
type K1 = { type: "K" };
type L1 = { type: "L" };
type M1 = { type: "M" };
type N1 = { type: "N" };
type O1 = { type: "O" };
type P1 = { type: "P" };
type Q1 = { type: "Q" };
type R1 = { type: "R" };
type S1 = { type: "S" };
type T1 = { type: "T" };
type U1 = { type: "U" };
type V1 = { type: "V" };
type W1 = { type: "W" };
type X1 = { type: "X" };
type Y1 = { type: "Y" };
type Z1 = { type: "Z" };

type union = A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z;

type union1 = A1|B1|C1|D1|E1|F1|G1|H1|I1|J1|K1|L1|M1|N1|O1|P1|Q1|R1|S1|T1|U1|V1|W1|X1|Y1|Z1;

// error
const foo = (x: union1): union => {
  return {
    type: x.type,
  };
};

const bar = (x: union1): union => {
  return x;
};

const xyz = (): union => {
  return {
    type: "A",
  };
};
//error
const abc = (x: union1): union => {
  return {
    type: x.type as union["type"],
  };
};

type shrinkUnion = A | B | C | D;
type shrinkUnion1 = A1 | B1 | C1 | D1;

const foo1 = (x: shrinkUnion1): shrinkUnion => {
  return {
    type: x.type,
  };
};

const bar1 = (x: shrinkUnion1): shrinkUnion => {
  return x;
};

const xyz1 = (): union => {
  return {
    type: "A",
  };
};

const abc1 = (x: shrinkUnion1): shrinkUnion => {
  return {
    type: x.type as shrinkUnion["type"],
  };
};

🙁 Actual behavior

failed to assign union1['type'] | union['type'] to union's type

🙂 Expected behavior

it should enable the assignment;

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions