Comment

Comment by thomasrognon

You need

  "noUncheckedIndexedAccess": true
in your tsconfig.json. For odd only numbers, you can make a "branded" type. There are many options, one way is

  type OddNumber = number & { __BRAND_ODD_NUMBER: true }
then it's just

  OddNumber[]
and to onboard untrusted data, use a type guard

  const isOddNumber = (x: unknown): x is OddNumber => typeof x === 'number' && x % 2 === 1

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