This can be done with a type lookup, although it looks like you might have to use an as
cast when you pass the parameter to make sure typescript knows its the right input type:
type Output<I> = I extends InputA ? OutputA
: I extends InputB ? OutputB
: I extends InputC ? OutputC
: never;
function transform<I>(input: I): Output<I> {
// todo
}
const a = transform({ type: "a" } as InputA);
// ^? OutputA
const b = transform({ type: "b" } as InputB);
// ^? OutputB
const c = transform({ something: "else" } as InputC);
// ^? OutputC
The as
cast may not be needed, providing Typescript can infer the type from elsewhere.