I have a line of code that grabs the value from an array of selected options (each option contains a value and label). value will never be undefined:
let marketplaces: string[] = selectedMarketplaces.map(m => m.value)
Instead I get error because typescript treats it as a union of string and undefined:
Argument of type '(string | undefined)[]' is not assignable to parameter of type 'string[]'.
To try to workaround, I tried to explicitly filter undefined
let marketplaces: string[] = selectedMarketplaces.map(m => m.value).filter(v => v !== undefined);
But still got the same error message. How do I work around this?