TypeScript/tests/cases/compiler/typePredicateWithThisParameter.ts

27 lines
400 B
TypeScript
Raw Normal View History

2017-04-23 02:09:20 +02:00
// Repro from #15310
interface Foo {
foo: string;
}
interface Bar {
bar: string;
}
function isFoo1(object: {}): object is Foo {
return 'foo' in object;
}
function isFoo2(this: void, object: {}): object is Foo {
return 'foo' in object;
}
declare let test: Foo | Bar;
if (isFoo1(test)) {
test.foo = 'hi';
}
if (isFoo2(test)) {
test.foo = 'hi';
}