I have a function type:
type Func = (param1: string, param2: number) => Promise<void>;
I want to validate functions using this type. But TS only throws error when the type is incompatible but not when the parameters are not present. Example:
const f1: Func = async () => {}; // need error here
const f2: Func = async (param1: string) => {}; // need error here
const f3: Func = async (param1: number) => {}; // TS throws error here only.
f1andf2are validFuncs, both of them can be calledfX("", 0)perfectly happily. Even if they declared both parameters, you can't force the implementation to use them, so what's the point?Funcwhich works the way you want. You could write some kind of generic helper function so thatcheck(f)only works iff's arguments are known to be "exactly"[string ,number], but that's not how TS works. See the linked q/a for more info.