Closed
Description
Bug Report
π Search Terms
- keyof union generic
- keyof union
- keyof
π Version & Regression Information
- Since 4.1.5 (Playground test where mapping works)
β― Playground Link
Playground link with relevant code
π» Code
type Fruit =
| {
name: "apple";
color: "red";
}
| {
name: "banana";
color: "yellow";
}
| {
name: "orange";
color: "orange";
};
type Result1<T extends {name: string | number; color: string | number }> = {
[Key in T as `${Key['name']}:${Key['color']}`]: unknown
};
type Result2<T extends {name: string | number; color: string | number }> = keyof {
[Key in T as `${Key['name']}:${Key['color']}`]: unknown
}
// should be "apple:red" | "banana:yellow" | "orange:orange"
type Test1 = keyof Result1<Fruit> // this works
// should be "apple:red" | "banana:yellow" | "orange:orange"
type Test2 = Result2<Fruit> // this doesn't work and I'm not sure why :D
π Actual behavior
- Test2 is
"apple:red" | "apple:yellow" | "apple:orange" | "banana:red" | "banana:yellow" | "banana:orange" | "strawberry:red" | "strawberry:yellow" | "strawberry:orange"
- Somehow
Result2
is collapsed:
π Expected behavior
- Test2 should be
"apple:red" | "banana:yellow" | "orange:orange"