|
| 1 | +tests/cases/compiler/keyofIsLiteralContexualType.ts(5,9): error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'. |
| 2 | + Type '"a" | "b" | "c"' is not assignable to type 'keyof T'. |
| 3 | + Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'. |
| 4 | + Type '"c"' is not assignable to type '"a" | "b"'. |
| 5 | + Type '"c"' is not assignable to type 'keyof T'. |
| 6 | + Type '"c"' is not assignable to type '"a" | "b"'. |
| 7 | +tests/cases/compiler/keyofIsLiteralContexualType.ts(13,11): error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'. |
| 8 | + |
| 9 | + |
| 10 | +==== tests/cases/compiler/keyofIsLiteralContexualType.ts (2 errors) ==== |
| 11 | + // keyof T is a literal contextual type |
| 12 | + |
| 13 | + function foo<T extends { a: string, b: string }>() { |
| 14 | + let a: (keyof T)[] = ["a", "b"]; |
| 15 | + let b: (keyof T)[] = ["a", "b", "c"]; |
| 16 | + ~ |
| 17 | +!!! error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'. |
| 18 | +!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type 'keyof T'. |
| 19 | +!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'. |
| 20 | +!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'. |
| 21 | +!!! error TS2322: Type '"c"' is not assignable to type 'keyof T'. |
| 22 | +!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'. |
| 23 | + } |
| 24 | + |
| 25 | + // Repro from #12455 |
| 26 | + |
| 27 | + declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>; |
| 28 | + |
| 29 | + let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]); |
| 30 | + let b = x.b; // Error |
| 31 | + ~ |
| 32 | +!!! error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'. |
0 commit comments