Deviopath › TypeScript

Keep Only Strings

Easy · Narrowing

Write a type guard isString(value: unknown): value is string, then use it in onlyStrings(values: unknown[]): string[] to keep only the string values, in their original order.

Passing a type guard to filter makes TypeScript know the result is string[].

Next: Generic First Item