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
|
=== tests/cases/compiler/typePredicateWithThisParameter.ts ===
// Repro from #15310
interface Foo {
foo: string;
>foo : string
}
interface Bar {
bar: string;
>bar : string
}
function isFoo1(object: {}): object is Foo {
>isFoo1 : (object: {}) => object is Foo
>object : {}
return 'foo' in object;
>'foo' in object : boolean
>'foo' : "foo"
>object : {}
}
function isFoo2(this: void, object: {}): object is Foo {
>isFoo2 : (this: void, object: {}) => object is Foo
>this : void
>object : {}
return 'foo' in object;
>'foo' in object : boolean
>'foo' : "foo"
>object : {}
}
declare let test: Foo | Bar;
>test : Foo | Bar
if (isFoo1(test)) {
>isFoo1(test) : boolean
>isFoo1 : (object: {}) => object is Foo
>test : Foo | Bar
test.foo = 'hi';
>test.foo = 'hi' : "hi"
>test.foo : string
>test : Foo
>foo : string
>'hi' : "hi"
}
if (isFoo2(test)) {
>isFoo2(test) : boolean
>isFoo2 : (this: void, object: {}) => object is Foo
>test : Foo | Bar
test.foo = 'hi';
>test.foo = 'hi' : "hi"
>test.foo : string
>test : Foo
>foo : string
>'hi' : "hi"
}
|