Typescript

Filter undefined & properly type the output

https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates (opens in a new tab)

export const isDefined = <T>(argument: T | undefined): argument is T =>
  argument !== undefined
 
const definedArray = withUndefined.filter(isDefined)

Otherwise TS doesn't infer that the result is defined.

Remove unused exports

External library

ts-prune

or knip

CC BY-NC 4.0 2024 © Shu Ding.