TypeScript, --strictNullChecks mode.
Suppose I have an array of null strings (string | null) []. What would be a single expression method to remove all zeros so that the result has a string like []?
const array: (string | null)[] = ["foo", "bar", null, "zoo", null]; const filterdArray: string[] = ???;
Array.filter does not work here:
// Type '(string | null)[]' is not assignable to type 'string[]' array.filter(x => x != null);
Arrays may work, but they are not supported by TypeScript.
In fact, the question can be generalized to the problem of filtering an array of any type of union by deleting records from one union from one element. But let me focus on joins with null and possibly undefined, as these are the most common use cases.
source share