Add more tests

This commit is contained in:
Anders Hejlsberg
2016-08-08 09:44:43 -07:00
parent a0c5608770
commit ce5a3f466d
2 changed files with 50 additions and 0 deletions

View File

@@ -77,4 +77,23 @@ function foo(x: A | undefined) {
x; // A
}
x; // A
}
// X is neither assignable to Y nor a subtype of Y
// Y is assignable to X, but not a subtype of X
interface X {
x?: string;
}
class Y {
y: string;
}
function goo(x: X) {
x;
if (x instanceof Y) {
x.y;
}
x;
}

View File

@@ -0,0 +1,31 @@
// Repro from #10145
interface A { type: 'A' }
interface B { type: 'B' }
function isA(x: A | B): x is A { return x.type === 'A'; }
function isB(x: A | B): x is B { return x.type === 'B'; }
function foo1(x: A | B): any {
x; // A | B
if (isA(x)) {
return x; // A
}
x; // B
if (isB(x)) {
return x; // B
}
x; // never
}
function foo2(x: A | B): any {
x; // A | B
if (x.type === 'A') {
return x; // A
}
x; // B
if (x.type === 'B') {
return x; // B
}
x; // never
}