I need help ensuring that a function in TypeScript returns a specific type based on a parameter. How can I make TypeScript understand my intention in this scenario?
type X = 'x'
type Y = 'y'
const customFunc = <Type extends X | Y>(input: Type): Type extends X ? 'result_x': 'result_y' => {
if (input === 'x') return 'result_x'
return 'result_y'
}
// The output type here will be 'result_x'
const outputX = customFunc('x')
// The output type here will be 'result_y'
const outputY = customFunc('y')