TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts
Anders Hejlsberg 7c45c7ba9f Fixing tests
2016-03-22 10:50:06 -07:00

25 lines
No EOL
401 B
TypeScript

// @declaration: true
type Kind = "A" | "B"
function kindIs(kind: Kind, is: "A"): kind is "A";
function kindIs(kind: Kind, is: "B"): kind is "B";
function kindIs(kind: Kind, is: Kind): boolean {
return kind === is;
}
var x: Kind = undefined;
if (kindIs(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!kindIs(x, "B")) {
let c = x;
}
else {
let d = x;
}