Add tests

This commit is contained in:
Anders Hejlsberg 2018-10-01 16:21:35 -07:00
parent 2801c97164
commit 34994627f0
2 changed files with 20 additions and 8 deletions

View File

@ -302,23 +302,16 @@ type S2 = {
b: string;
};
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]) {
x1 = x2;
x1 = x3;
x1 = x4;
x2 = x1;
x2 = x3;
x2 = x4;
x3 = x1;
x3 = x2;
x3 = x4;
x4 = x1;
x4 = x2;
x4 = x3;
x1.length;
x2.length;
x3.length;
x4.length;
}
function f91<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {

View File

@ -122,3 +122,22 @@ function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
k = 42; // error
k = "hello"; // error
}
// Repro from #27470
type UndefinedKeys<T extends Record<string, any>> = {
[K in keyof T]: undefined extends T[K] ? K : never
};
type MyType = {a: string, b: string | undefined}
type Result1 = UndefinedKeys<MyType>;
const a1: Result1['a'] = 'a'; // Error
const b1: Result1['b'] = 'b';
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
t[k] = 42; // Error
t[k] = "hello"; // Error
t[k] = [10, 20]; // Error
}