I'm using TypeScript 2.9.2.
A 3rd party library URI.js has a static method declared as:
joinPaths(...paths: (string | URI)[]): URI;
Now I have a variable named urlPaths declared as urlPaths: string | string[], the following code is giving me error [ts] Expression expected. at the spread operator:
URI.joinPaths(typeof urlPaths === 'string' ? urlPaths as string : ...(urlPaths as string[]))
But if I extract the ternary operator expression out as a separate variable, it is fine:
const paths = typeof urlPaths === 'string' ? [urlPaths as string] : urlPaths as string[];
URI.joinPaths(...paths);
What's wrong with my syntax here?