type FuncType<O extends Object> = (option: O) => boolean
export const funcMap: Map<string, Function> = new Map()
const func1: FuncType<Object> = () => true
const func2: FuncType<{prop: number}> = ({ prop }) => prop !== 0
funcMap.set('func1', func1)
funcMap.set('func2', func2)
In a separate file..
const _func2 = funcMap.get('func2')
if (_func2 !== undefined) _func2() // here I am expecting the type FuncType<{prop: number}>
The type of _func2()
is currently being recognized as Function.
I see why this is happening.
How can I adjust my TypeScript code to infer and return the expected type from Map.get()?