DEV Community

Discussion on: Advanced TypeScript Exercises - Answer 4

Collapse
 
kolharsam profile image
kolharsam

I would like to use unknown over any in AppendArgument. Because I would prefer not to get past type checking using any.

type AppendArgument<F extends (...args: unknown[]) => unknown, A> =
    (x: A, ...args: Parameters<F>) => ReturnType<F>;

type FinalF = AppendArgument<(a: number, b: string) => number, boolean>;  // this gives an error since the function parameters cannot be mapped to `unknown`
Enter fullscreen mode Exit fullscreen mode

Any ideas of how I can change this?

Collapse
 
macsikora profile image
Pragmatic Maciej • Edited

Extends any[] doesn't mean it is any[] it only means it is any array, so array with any type you want. Compiler will infer correct type and it will never be any. There is no type whole here