I am currently utilizing TypeScript version 2.9.2.
There is a static method in a third-party library called URI.js, which is declared as follows:
joinPaths(...paths: (string | URI)[]): URI;
I have a variable named urlPaths
that is defined as urlPaths: string | string[]
. The code below is causing an error [ts] Expression expected.
at the spread operator:
URI.joinPaths(typeof urlPaths === 'string' ? urlPaths as string : ...(urlPaths as string[]))
However, if I separate the ternary operator expression into its own variable, it works without errors:
const paths = typeof urlPaths === 'string' ? [urlPaths as string] : urlPaths as string[];
URI.joinPaths(...paths);
What could be incorrect with my syntax in this scenario?