Add tests

This commit is contained in:
Anders Hejlsberg 2018-09-17 13:01:53 -07:00
parent 92c17cebcb
commit eb06af1901
2 changed files with 33 additions and 0 deletions

View File

@ -68,3 +68,30 @@ function f6() {
y; // string | undefined
}
}
function f7(x: {}) {
if (x) {
x; // {}
}
else {
x; // {}
}
}
function f8<T>(x: T) {
if (x) {
x; // {}
}
else {
x; // {}
}
}
function f9<T extends object>(x: T) {
if (x) {
x; // {}
}
else {
x; // never
}
}

View File

@ -116,3 +116,9 @@ function f3<T, K extends Extract<keyof T, string>, U extends T, J extends K>(
tk = uj;
uj = tk; // error
}
// The constraint of 'keyof T' is 'keyof T'
function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
k = 42; // error
k = "hello"; // error
}