1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
=== tests/cases/compiler/discriminantsAndTypePredicates.ts ===
// Repro from #10145
interface A { type: 'A' }
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>type : Symbol(A.type, Decl(discriminantsAndTypePredicates.ts, 2, 13))
interface B { type: 'B' }
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
function isA(x: A | B): x is A { return x.type === 'A'; }
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
function isB(x: A | B): x is B { return x.type === 'B'; }
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
function foo1(x: A | B): any {
>foo1 : Symbol(foo1, Decl(discriminantsAndTypePredicates.ts, 6, 57))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
x; // A | B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
if (isA(x)) {
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
return x; // A
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
}
x; // B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
if (isB(x)) {
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
return x; // B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
}
x; // never
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
}
function foo2(x: A | B): any {
>foo2 : Symbol(foo2, Decl(discriminantsAndTypePredicates.ts, 18, 1))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
x; // A | B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
if (x.type === 'A') {
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
return x; // A
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
}
x; // B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
if (x.type === 'B') {
>x.type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
return x; // B
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
}
x; // never
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
}
|