Closed
Description
Bug Report
Cannot use mapped types to create new mapped types. I have no idea why this would happen because the types are computed correctly.
🔎 Search Terms
- mapped types
🕗 Version & Regression Information
This changed between version 4.5.5 and 4.6.2.
⏯ Playground Link
Playground link with relevant code
💻 Code
function makeCompleteLookupMapping<T extends ReadonlyArray<any>, Attr extends keyof T[number]>(
ops: T,
attr: Attr,
): {
[Item in T[number]as Item[Attr]]: Item;
} {
return Object.fromEntries(
ops.map(op => [op[attr], op] as const),
);
}
const ALL_BARS = [
{ name: 'a'},
{name: 'b'},
] as const;
const BAR_LOOKUP = makeCompleteLookupMapping(ALL_BARS, 'name')
type BarLookup = typeof BAR_LOOKUP;
type Baz = { [K in keyof BarLookup]: BarLookup[K]['name']; };
🙁 Actual behavior
I cannot use name
to index BarLookup[K]
where K
is a keyof BarLookup
.
🙂 Expected behavior
I expect type Baz
to be {a: 'a', b:'b'}
.