157 lines
2.9 KiB
Text
157 lines
2.9 KiB
Text
=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormIsType.ts ===
|
|
|
|
class C1 {
|
|
>C1 : C1
|
|
|
|
p1: string;
|
|
>p1 : string
|
|
}
|
|
class C2 {
|
|
>C2 : C2
|
|
|
|
p2: number;
|
|
>p2 : number
|
|
}
|
|
class D1 extends C1 {
|
|
>D1 : D1
|
|
>C1 : C1
|
|
|
|
p3: number;
|
|
>p3 : number
|
|
}
|
|
var str: string;
|
|
>str : string
|
|
|
|
var num: number;
|
|
>num : number
|
|
|
|
var strOrNum: string | number;
|
|
>strOrNum : string | number
|
|
|
|
function isC1(x: any): x is C1 {
|
|
>isC1 : (x: any) => boolean
|
|
>x : any
|
|
>x : any
|
|
>C1 : C1
|
|
|
|
return true;
|
|
>true : boolean
|
|
}
|
|
|
|
function isC2(x: any): x is C2 {
|
|
>isC2 : (x: any) => boolean
|
|
>x : any
|
|
>x : any
|
|
>C2 : C2
|
|
|
|
return true;
|
|
>true : boolean
|
|
}
|
|
|
|
function isD1(x: any): x is D1 {
|
|
>isD1 : (x: any) => boolean
|
|
>x : any
|
|
>x : any
|
|
>D1 : D1
|
|
|
|
return true;
|
|
>true : boolean
|
|
}
|
|
|
|
var c1Orc2: C1 | C2;
|
|
>c1Orc2 : C1 | C2
|
|
>C1 : C1
|
|
>C2 : C2
|
|
|
|
str = isC1(c1Orc2) && c1Orc2.p1; // C1
|
|
>str = isC1(c1Orc2) && c1Orc2.p1 : string
|
|
>str : string
|
|
>isC1(c1Orc2) && c1Orc2.p1 : string
|
|
>isC1(c1Orc2) : boolean
|
|
>isC1 : (x: any) => boolean
|
|
>c1Orc2 : C1 | C2
|
|
>c1Orc2.p1 : string
|
|
>c1Orc2 : C1
|
|
>p1 : string
|
|
|
|
num = isC2(c1Orc2) && c1Orc2.p2; // C2
|
|
>num = isC2(c1Orc2) && c1Orc2.p2 : number
|
|
>num : number
|
|
>isC2(c1Orc2) && c1Orc2.p2 : number
|
|
>isC2(c1Orc2) : boolean
|
|
>isC2 : (x: any) => boolean
|
|
>c1Orc2 : C1 | C2
|
|
>c1Orc2.p2 : number
|
|
>c1Orc2 : C2
|
|
>p2 : number
|
|
|
|
str = isD1(c1Orc2) && c1Orc2.p1; // D1
|
|
>str = isD1(c1Orc2) && c1Orc2.p1 : string
|
|
>str : string
|
|
>isD1(c1Orc2) && c1Orc2.p1 : string
|
|
>isD1(c1Orc2) : boolean
|
|
>isD1 : (x: any) => boolean
|
|
>c1Orc2 : C1 | C2
|
|
>c1Orc2.p1 : string
|
|
>c1Orc2 : D1
|
|
>p1 : string
|
|
|
|
num = isD1(c1Orc2) && c1Orc2.p3; // D1
|
|
>num = isD1(c1Orc2) && c1Orc2.p3 : number
|
|
>num : number
|
|
>isD1(c1Orc2) && c1Orc2.p3 : number
|
|
>isD1(c1Orc2) : boolean
|
|
>isD1 : (x: any) => boolean
|
|
>c1Orc2 : C1 | C2
|
|
>c1Orc2.p3 : number
|
|
>c1Orc2 : D1
|
|
>p3 : number
|
|
|
|
var c2Ord1: C2 | D1;
|
|
>c2Ord1 : C2 | D1
|
|
>C2 : C2
|
|
>D1 : D1
|
|
|
|
num = isC2(c2Ord1) && c2Ord1.p2; // C2
|
|
>num = isC2(c2Ord1) && c2Ord1.p2 : number
|
|
>num : number
|
|
>isC2(c2Ord1) && c2Ord1.p2 : number
|
|
>isC2(c2Ord1) : boolean
|
|
>isC2 : (x: any) => boolean
|
|
>c2Ord1 : C2 | D1
|
|
>c2Ord1.p2 : number
|
|
>c2Ord1 : C2
|
|
>p2 : number
|
|
|
|
num = isD1(c2Ord1) && c2Ord1.p3; // D1
|
|
>num = isD1(c2Ord1) && c2Ord1.p3 : number
|
|
>num : number
|
|
>isD1(c2Ord1) && c2Ord1.p3 : number
|
|
>isD1(c2Ord1) : boolean
|
|
>isD1 : (x: any) => boolean
|
|
>c2Ord1 : C2 | D1
|
|
>c2Ord1.p3 : number
|
|
>c2Ord1 : D1
|
|
>p3 : number
|
|
|
|
str = isD1(c2Ord1) && c2Ord1.p1; // D1
|
|
>str = isD1(c2Ord1) && c2Ord1.p1 : string
|
|
>str : string
|
|
>isD1(c2Ord1) && c2Ord1.p1 : string
|
|
>isD1(c2Ord1) : boolean
|
|
>isD1 : (x: any) => boolean
|
|
>c2Ord1 : C2 | D1
|
|
>c2Ord1.p1 : string
|
|
>c2Ord1 : D1
|
|
>p1 : string
|
|
|
|
var r2: C2 | D1 = isC1(c2Ord1) && c2Ord1; // C2 | D1
|
|
>r2 : C2 | D1
|
|
>C2 : C2
|
|
>D1 : D1
|
|
>isC1(c2Ord1) && c2Ord1 : D1
|
|
>isC1(c2Ord1) : boolean
|
|
>isC1 : (x: any) => boolean
|
|
>c2Ord1 : C2 | D1
|
|
>c2Ord1 : D1
|
|
|