For convenience, I hope that the object can directly call:
function createCallableObject<T, Fn = (payload?: Partial<T>) => any>(initState: T, fn: Fn) {
const state: any = fn;
Object.setPrototypeOf(state, null);
delete state.name;
delete state.length;
Object.assign(state, initState);
// TODO: type
return state as Fn & T;
}
The objects generated by createCallableObject
will display some functions property i don’t want:
I have tried:
Omit<Fn, keyof Fn>
but type error: Type 'Fn' has no call signatures
1