I have a <Selector /> component which can accept an optional param isMulti: boolean.
It also have a required param onSelected, who's signature should be changed based on isMulti value (wheater is true or not - undefined)
I've created an example here
My typescript implementation fails somewhere in the following implementation (I think):
interface ISelectorProps<T> {
isMulti?: T;
onSelected: T extends true
? ((options: string[]) => void)
: ((option: string) => void);
}
So the idea is that, if isMulti is provided, onSelected should return an array of strings, otherwise, it should provide only a string;
As you can see in the editor, TS complains here:
Argument of type 'string[]' is not assignable to parameter of type 'string & string[]'.
Type 'string[]' is not assignable to type 'string'.
The signature of onSelected is wrongly typed. Any ideas?
