Closed
Description
🔎 Search Terms
generic function, partial, optional, mapped type, indexed access, undefined, bug, regression
🕗 Version & Regression Information
- This is a bug
- This changed between versions 4.5.5 and 4.6.2
- This is the behavior in every version I tried (all playground versions)
⏯ Playground Link
💻 Code
type Obj = {
a: 1,
b: 2
};
const mapped: {
[K in keyof Partial<Obj>]: Obj[K]
} = {}
const resolveMapped = <K extends keyof typeof mapped>(key: K) => mapped[key].toString();
// ^-- Error expected (`mapped[key]` is possibly undefined)
🙁 Actual behavior
TypeScript does not recognize mapper[key]
might be undefined and emits broken code without errors
🙂 Expected behavior
Correct type inference from pre-v4.6.x
Additional information about the issue
No response