TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndTuples01.ts
2015-10-02 16:30:22 -07:00

20 lines
No EOL
464 B
TypeScript

// @declaration: true
// Should all be strings.
let [hello, brave, newish, world] = ["Hello", "Brave", "New", "World"];
type RexOrRaptor = "t-rex" | "raptor"
let [im, a, dinosaur]: ["I'm", "a", RexOrRaptor] = ['I\'m', 'a', 't-rex'];
rawr(dinosaur);
function rawr(dino: RexOrRaptor) {
if (dino === "t-rex") {
return "ROAAAAR!";
}
if (dino === "raptor") {
return "yip yip!";
}
throw "Unexpected " + dino;
}