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
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts ===
interface I { global: string; }
>global : string
var result!: I;
>result : I
var result2!: I;
>result2 : I
if (!(result instanceof RegExp)) {
>!(result instanceof RegExp) : boolean
>(result instanceof RegExp) : boolean
>result instanceof RegExp : boolean
>result : I
>RegExp : RegExpConstructor
result = result2;
>result = result2 : I
>result : I
>result2 : I
} else if (!result.global) {
>!result.global : boolean
>result.global : any
>result : never
>global : any
}
// Repro from #31155
interface OnChanges {
onChanges(changes: Record<string, unknown>): void
>onChanges : (changes: Record<string, unknown>) => void
>changes : Record<string, unknown>
}
interface Validator {
validate(): null | Record<string, unknown>;
>validate : () => null | Record<string, unknown>
>null : null
}
class C {
>C : C
validate() {
>validate : () => {}
return {}
>{} : {}
}
}
function foo() {
>foo : () => void
let v: Validator & Partial<OnChanges> = null as any;
>v : Validator & Partial<OnChanges>
>null as any : any
>null : null
if (v instanceof C) {
>v instanceof C : boolean
>v : Validator & Partial<OnChanges>
>C : typeof C
v // Validator & Partial<OnChanges> & C
>v : C
}
v // Validator & Partial<OnChanges> via subtype reduction
>v : C | (Validator & Partial<OnChanges>)
// In 4.1, we introduced a change which _fixed_ a bug with CFA
// correctly setting this to be the right object. With 4.2,
// we reverted that fix in #42231 which brought behavior back to
// before 4.1.
if (v.onChanges) {
>v.onChanges : any
>v : C | (Validator & Partial<OnChanges>)
>onChanges : any
v.onChanges({});
>v.onChanges({}) : any
>v.onChanges : any
>v : C | (Validator & Partial<OnChanges>)
>onChanges : any
>{} : {}
}
}
|