1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
=== tests/cases/compiler/contextualTypeOfIndexedAccessParameter.ts ===
type Keys = "a" | "b";
>Keys : "a" | "b"
type OptionsForKey = { a: { cb: (p: number) => number } } & { b: {} };
>OptionsForKey : { a: { cb: (p: number) => number; }; } & { b: {}; }
>a : { cb: (p: number) => number; }
>cb : (p: number) => number
>p : number
>b : {}
declare function f<K extends Keys>(key: K, options: OptionsForKey[K]): void;
>f : <K extends Keys>(key: K, options: OptionsForKey[K]) => void
>key : K
>options : OptionsForKey[K]
f("a", {
>f("a", { cb: p => p,}) : void
>f : <K extends Keys>(key: K, options: OptionsForKey[K]) => void
>"a" : "a"
>{ cb: p => p,} : { cb: (p: number) => number; }
cb: p => p,
>cb : (p: number) => number
>p => p : (p: number) => number
>p : number
>p : number
});
function g<
>g : <K extends "a" | "b">(x: ({ a: string;} & { b: string;})[K], y: string) => void
K extends "a" | "b">(x: ({ a: string } & { b: string })[K], y: string) {
>x : ({ a: string; } & { b: string; })[K]
>a : string
>b : string
>y : string
x = y;
>x = y : string
>x : ({ a: string; } & { b: string; })[K]
>y : string
}
|