Added tests for operations that use assignable to/from.

This commit is contained in:
Daniel Rosenwasser 2015-10-26 15:42:02 -07:00
parent 049d02f871
commit 6618fd21bf
4 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,17 @@

type S = "a" | "b";
type T = S[] | S;
function f(foo: T) {
if (foo === "a") {
return foo;
}
else if (foo === "b") {
return foo;
}
else {
return (foo as S[])[0];
}
throw new Error("Unreachable code hit.");
}

View file

@ -0,0 +1,18 @@

type S = "a" | "b";
type T = S[] | S;
function isS(t: T): t is S {
return t === "a" || t === "b";
}
function f(foo: T) {
if (isS(foo)) {
return foo;
}
else {
return foo[0];
}
throw new Error("Unreachable code hit.");
}

View file

@ -0,0 +1,13 @@

type S = "a" | "b";
type T = S[] | S;
var foo: T;
switch (foo) {
case "a":
case "b":
break;
default:
foo = (foo as S[])[0];
break;
}

View file

@ -0,0 +1,31 @@

type S = "a" | "b";
type T = S[] | S;
var s: S;
var t: T;
var str: string;
////////////////
s = <S>t;
s = t as S;
s = <S>str;
s = str as S;
////////////////
t = <T>s;
t = s as T;
t = <T>str;
t = str as T;
////////////////
str = <string>s;
str = s as string;
str = <string>t;
str = t as string;