Closed as not planned
Closed as not planned
Description
Bug Report
π Search Terms
mapped type origin generic indexed access satisfies
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
type MyMap = {
"move-forward": { distance: number };
stop: { cause: string };
};
type Values<T> = T[keyof T];
type Union<P extends keyof MyMap = keyof MyMap> = Values<
{
[K in P]: { type: K } & MyMap[K];
}
>;
// const action: { [K in keyof MyMap]: (move: MyMap[K]) => void } = {
// "move-forward": (move) =>
// console.log("Moving forward by distance:", move.distance),
// stop: (move) => console.log("Stopping. Cause:", move.cause),
// };
const action = {
"move-forward": (move) =>
console.log("Moving forward by distance:", move.distance),
stop: (move) => console.log("Stopping. Cause:", move.cause),
} satisfies { [K in keyof MyMap]: (move: MyMap[K]) => void };
function execute<K extends keyof MyMap>(move: Union<K>) {
action[move.type](move); // errors but it should be OK just like the variant with the declared type
}
π Actual behavior
It errors on the action[move.type](move)
call within the generic function.
π Expected behavior
It should be OK just like the variant with the declared type.