I have this:
const any = (any?: any): any => any;
export type Fn = (cb: (...args: (string | number)[]) => any) => any;
const Fn: Fn = any();
const t1 = Fn((x: unknown) => x); // Allowed
const t2 = Fn(<X>(x: X) => x); // Allowed
How can i disallow unknown parameters inside the callback?
I have tried:
- Setting
strictFunctionTypes
insidetsconfig.json
- Using an
Exact
utility type - Using a generic on the
cb
declaration
None of these have worked for me so far.
So, how do I avoid callbacks without constrained arguments.
Here is what should be allowed:
const t3 = Fn((a: string, b: number) => {});
const t4 = Fn(() => {});
const t5 = Fn((x: string | number, y: string) => {});
const t6 = Fn(<X extends number>(x: X) => x);
const t7 = Fn(<X extends string, Y extends string>(x: X, y: Y) => x + y);
Currently most of these don’t work either…
How can I solve this issue?
Playground
8