The built in
Array.filter method cannot be used to filter array items in a type safe way. To exclude some items on the type level we would need a typecast. Are there any better alternatives?
To demonstrate this, let’s say we have a basket of apples and oranges. We want to make some fresh orange juice. And of course all that using TypeScript.
Our first approach might look like this:
// Let's pretend this function is a juice squeezer
Note that this example uses type literals extensively to make it more concise.