Added tests for string literal types used as generic constraints.

This commit is contained in:
Daniel Rosenwasser 2015-11-10 14:40:19 -08:00
parent f80a6c6e86
commit 2a370c9aa7
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// @declaration: true
function foo<T extends "foo">(f: (x: T) => T) {
return f;
}
function bar<T extends "foo" | "bar">(f: (x: T) => T) {
return f;
}
let f = foo(x => x);
let fResult = f("foo");
let g = foo((x => x));
let gResult = g("foo");
let h = bar(x => x);
let hResult = h("foo");
hResult = h("bar");

View File

@ -0,0 +1,8 @@
// @declaration: true
function foo<T extends "foo">(f: (x: T) => T) {
return f;
}
let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo");
let fResult = f("foo");