-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
An indexed access type { [P in K]: E }[X]
should be assignable to an instantiation of E
with X
substituted for P
.
This issue was originally reported here.
🔎 Search Terms
Mapped type indexed access.
🕗 Version & Regression Information
Nightly build
⏯ Playground Link
Playground link with relevant code
💻 Code
type ArgMap = { a: number, b: string };
type Func<K extends keyof ArgMap> = (x: ArgMap[K]) => void;
type Funcs = { [K in keyof ArgMap]: Func<K> };
function f1<K extends keyof ArgMap>(funcs: Funcs, key: K, arg: ArgMap[K]) {
funcs[key](arg);
}
function f2<K extends keyof ArgMap>(funcs: Funcs, key: K, arg: ArgMap[K]) {
const func = funcs[key]; // Type Funcs[K]
func(arg);
}
function f3<K extends keyof ArgMap>(funcs: Funcs, key: K, arg: ArgMap[K]) {
const func: Func<K> = funcs[key]; // Error, Funcs[K] not assignable to Func<K>
func(arg);
}
🙁 Actual behavior
Unexpected error in example above.
🙂 Expected behavior
No errors in example above.
jcalz
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue