|
| 1 | +=== tests/cases/compiler/consistentUnionSubtypeReduction.ts === |
| 2 | +// https://github.com/microsoft/TypeScript/issues/31155 |
| 3 | + |
| 4 | +declare const MyArray: { |
| 5 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 6 | + |
| 7 | + isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[]; |
| 8 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 9 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12)) |
| 10 | +>arg : Symbol(arg, Decl(consistentUnionSubtypeReduction.ts, 3, 15)) |
| 11 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12)) |
| 12 | +>arg : Symbol(arg, Decl(consistentUnionSubtypeReduction.ts, 3, 15)) |
| 13 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12)) |
| 14 | + |
| 15 | +}; |
| 16 | + |
| 17 | +declare const a: readonly string[] | string; |
| 18 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13)) |
| 19 | + |
| 20 | +declare const b: string[] | string; |
| 21 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13)) |
| 22 | + |
| 23 | +declare const c: unknown; |
| 24 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13)) |
| 25 | + |
| 26 | +if (MyArray.isArray(a)) { |
| 27 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 28 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 29 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 30 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13)) |
| 31 | + |
| 32 | + a; // readonly string[] |
| 33 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13)) |
| 34 | +} |
| 35 | +else { |
| 36 | + a; // string |
| 37 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13)) |
| 38 | +} |
| 39 | +a; // readonly string[] | string; |
| 40 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13)) |
| 41 | + |
| 42 | +if (MyArray.isArray(b)) { |
| 43 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 44 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 45 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 46 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13)) |
| 47 | + |
| 48 | + b; // string[] | string; |
| 49 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13)) |
| 50 | +} |
| 51 | +else { |
| 52 | + b; // string |
| 53 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13)) |
| 54 | +} |
| 55 | +b; // string[] | string; |
| 56 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13)) |
| 57 | + |
| 58 | +if (MyArray.isArray(c)) { |
| 59 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 60 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 61 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 62 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13)) |
| 63 | + |
| 64 | + c; // any[] |
| 65 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13)) |
| 66 | +} |
| 67 | + |
| 68 | + |
| 69 | +function f<T>(x: T) { |
| 70 | +>f : Symbol(f, Decl(consistentUnionSubtypeReduction.ts, 28, 1)) |
| 71 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11)) |
| 72 | +>x : Symbol(x, Decl(consistentUnionSubtypeReduction.ts, 31, 14)) |
| 73 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11)) |
| 74 | + |
| 75 | + const a: readonly T[] | string = null!; |
| 76 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9)) |
| 77 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11)) |
| 78 | + |
| 79 | + const b: T[] | string = null!; |
| 80 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9)) |
| 81 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11)) |
| 82 | + |
| 83 | + const c: T = null!; |
| 84 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9)) |
| 85 | +>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11)) |
| 86 | + |
| 87 | + if (MyArray.isArray(a)) { |
| 88 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 89 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 90 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 91 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9)) |
| 92 | + |
| 93 | + a; // readonly T[] |
| 94 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9)) |
| 95 | + } |
| 96 | + else { |
| 97 | + a; // string |
| 98 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9)) |
| 99 | + } |
| 100 | + a; // readonly T[] | string; |
| 101 | +>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9)) |
| 102 | + |
| 103 | + if (MyArray.isArray(b)) { |
| 104 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 105 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 106 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 107 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9)) |
| 108 | + |
| 109 | + b; // T[] |
| 110 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9)) |
| 111 | + } |
| 112 | + else { |
| 113 | + b; // string |
| 114 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9)) |
| 115 | + } |
| 116 | + b; |
| 117 | +>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9)) |
| 118 | + |
| 119 | + if (MyArray.isArray(c)) { |
| 120 | +>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 121 | +>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13)) |
| 122 | +>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24)) |
| 123 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9)) |
| 124 | + |
| 125 | + c; // T & (T extends readonly any[] ? readonly any[] : any[]) |
| 126 | +>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9)) |
| 127 | + } |
| 128 | +} |
| 129 | + |
0 commit comments