Here is my code:
let someVar: Array<string>;
somevar = ["a", "b", undefined, "c"].filter((it) => !!it);
Above code gives error
Type '(string | undefined)[]' is not assignable to type 'string[]'.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
I am not sure how do I get rid of the error without changing the type of someVar
.
My actual case is that the type of variable is coming from an entity class that takes either an array of strings or is null. And this best represents the model.
So how do I fix this without modifying the type of someVar
?