-
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
Mapped type's element is not assignable to type T | undefined
where T
is unconstrained
π Search Terms
mapped types, TS2345, generic, not assignable
π Version & Regression Information
Regression in TS 4.2.3
β― Playground Link
Playground link with relevant code
π» Code
type MyMap<M extends object> = {
[K in keyof M]: {
x: number
}
}
declare function g<T>(value?: T): void;
function f<M extends object>(mymap: MyMap<M>, k: keyof any) {
const elemofM = mymap[k as keyof M]
g(elemofM)
//~~~~~~~ TS2345: Argument of type '{ x: number; }' is not assignable to parameter of type 'MyMap<M>[keyof M]'.
}
π Actual behavior
error TS2345: Argument of type '{ x: number; }' is not assignable to parameter of type 'MyMap[keyof M]'.
π Expected behavior
No error (it was not in TS 4.1)
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