Re:Flatten Arrays in Vanilla JavaScript with Flat() and Flat...
by amitport on Wednesday January 05, 2022 @10:07PM
(#29818780)
Oh so there is an overload!
filter<U extends T>(pred: (a: T) => a is U): U[];
Additionally, getting TS better at inferring type guards is an open issue (literally): https://github.com/microsoft/TypeScript/issues/38390
I don't know why the type isn't narrowed in Array.filter like it is in if statements without this weird workaround.
This example in Typescript playground: https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgJwXA...[1]: https://www.typescriptlang.org/docs/handbook/advanced-types....