Closed
Description
Bug Report
π Search Terms
indexed access types, mapped types
π Version & Regression Information
- This changed between versions 4.6.4 and 4.7.0
β― Playground Link
π» Code
type Types = {
first: { a1: true };
second: { a2: true };
third: { a3: true };
}
class Test {
entries: { [T in keyof Types]?: Types[T][] }
constructor() {
this.entries = {};
}
addEntry<T extends keyof Types>(name: T, entry: Types[T]) {
if (!this.entries[name]) {
this.entries[name] = [];
}
this.entries[name]?.push(entry); // error
}
}
π Actual behavior
Got the following error:
Argument of type '{ a1: true; } | { a2: true; } | { a3: true; }' is not assignable to parameter of type '{ a1: true; } & { a2: true; } & { a3: true; }'.
Type '{ a1: true; }' is not assignable to type '{ a1: true; } & { a2: true; } & { a3: true; }'.
Property 'a2' is missing in type '{ a1: true; }' but required in type '{ a2: true; }'
π Expected behavior
No error. Or maybe I missed something, and this was intentional.
Seems like it was fixed in #47109 and broken in v4.7.