Stricter type for fromNullable #1951
Lior-Kiperman
started this conversation in
General
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.
-
I'd like to strict the type of
fromNullable
of Option to allow only nullable values.Something like this:
export const fromNullable: <A extends null | undefined>(a: A) => O.Option<NonNullable>
This allows us to:
We use the eslint rule for "@typescript-eslint/no-unnecessary-condition", which helps us avoid useless checks for nulls and undefined and such. But when we use O.fromNullable it does not recognize it as an unnecessary condition.
I thought about overriding the type of fromNullable with - declare module 'fp-ts/Option'
Or adding a util function that simply calls O.fromNullable
Your thoughts and suggestions?
Beta Was this translation helpful? Give feedback.
All reactions