5 ms·
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
by thomasrognon 2y ago
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