Hugo Vinet
PostsTagsRSS

Aug 16, 2022 · typescript, developer experience, tooling

Typescript

Filter undefined & properly type the output

https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates

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

GitHubLinkedIn