mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Added tests for string literal types used as generic constraints.
This commit is contained in:
parent
f80a6c6e86
commit
2a370c9aa7
@ -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");
|
||||
@ -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");
|
||||
Loading…
x
Reference in New Issue
Block a user