Problem with Typescript Parameter Type Resolution:
functionBuilder
takes a parameter arg
and returns an object with a function property based on the value of arg
. If arg === 'a'
, the function expects a string
parameter, otherwise it expects a number
.
const functionBuilder = (arg: string) => {
if(arg === 'a'){
return {
f: (val: string) => {}
}
}
return {
f: (val: number) => {}
}
}
const f1 = functionBuilder('a');
The issue is that calling the function f
on f1
requires an argument of type never
instead of string