mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Add tests
This commit is contained in:
parent
2801c97164
commit
34994627f0
@ -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]) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user