I have function where the first argument determines the 2nd argument.
It acts similar to Foo
type stringF = (type: 'str', value: string) => void
type numberF = (type: 'num', value: number) => void
type booleanF = (type: 'bool', value: boolean) => void
...
...
declare const Foo: stringF & numberF & booleanF //& etc..
There were 6 functions types in total. It was a pain but manageable. However now there is an extra parameter as the first argument that specifies if it should be an array or not..
so it became:
type stringF = (arr: false, type: 'str', value: string) => void
type numberF = (arr, false, type: 'num', value: number) => void
type booleanF = (arr, false, type: 'bool', value: boolean) => void
...
type stringF = (arr: true, type: 'str', value: string[]) => void
type numberF = (arr, true, type: 'num', value: number[]) => void
type booleanF = (arr, true, type: 'bool', value: boolean[]) => void
...
Now there are 12 function types. And it doesn't seem worth the hassle to properly type the function
Is there any easier way to make conditional function signitures?