In vscode with typescript
multiple generic not infered properly when to use User-Defined Type Guards
const arraySample = [1, [3, 4], ["s"]];
const isFlat = <T, U>(array: (T | T[] | U | U[])[]): array is (T | U)[] => {
return !array.some(Array.isArray);
};
if (isFlat(arraySample)) {
arraySample;
}
vscode tooltip say below with error:
const isFlat: <number, number>(array: (number | number[])[]) => array is number[]
but I think it must be
const isFlat: <number, string>(array: (number | number[] | string | string[])[]) => array is (number|string)[]
could you let me know the proper solution?