I have a type that generates Function type with parameters from tuple provided as an arbitrarily long tuple, this is further transformed so that every param may be undefined:
export type Fn_With_Options<Args extends any[], Args_With_Option extends any[] = []>
= Args extends [infer Head, ...any[]]
? (Args extends [any, ... infer Tail]
? Fn_With_Options<Tail, [...Args_With_Option, Head | undefined]>
: never)
: (... args: Args_With_Option) => void
Here I_create some random function with three arguments:
type Test_Fn_Type
= Fn_With_Options<[first: string, second: number, third: boolean]>
Next I create test function that conforms to type generated, callable with undefined values as well
const test: Test_Fn_Type = (first, second, third) => {}
And finaly the ussage, there I would need to have the function’s return type to be typed based on the arguments user provided, but I am not sure whether this is possible to do with some clever trick, or whether I would need to resort to typing multiple lengths of parameter tuples manualy
// standart usage with some type
test("str", 42, true)
// other type of ussage, this will have different return type
test("str", undefined, true)