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