Comment

Comment by drabinowitz

Type guards also allow you to use Array.prototype.filter to modify the type of an array ie

  const maybePets: Array<Pet | undefined> = [...]
  const pets: Array<Pet> = maybePets.filter((v: Pet | undefined): v is Pet => v != undefined)
Will compile without errors.
parent drabinowitz 7 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton