'all' and TypeScript #135
Unanswered
davetapley
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a list of
number | undefined. I want to know if they're allnumber, and have it type check.I tried
all(isNotNil, data), but the types aren't narrowed (somewhat expected).So here's what I came up with, using type predicates, works but is a bit verbose:
If I hover
datain VSCode it shows the narrowed type correctly:If I switch for either of these I get
const data: (number | undefined)[]in both branches 😑Is there a more terse / less explicit way to do this?
Beta Was this translation helpful? Give feedback.
All reactions