I have a file with functions
// a.ts
export function foo(a: { test: number }): number {
return 0
}
export function bar(a: { balls: string }): number {
return 0
}
I have another file that takes the name of the function and calls it
// b.ts
import * as funcs from './a'
type Funcs = typeof funcs
type FuncName = keyof Funcs
function run<F extends FuncName>(func: F, params: Parameters<Funcs[F]>[0]) {
return funcs[func](params)
// funcs[func] has double params?
}
I am getting a strange error that:
Argument of type '{ test: number; } | { balls: string; }' is not assignable to parameter of type '{ test: number; } & { balls: string; }'.
Type '{ test: number; }' is not assignable to type '{ test: number; } & { balls: string; }'.
Property 'balls' is missing in type '{ test: number; }' but required in type '{ balls: string; }'```