ramda/types

Make `isNotNil` a type guard

Closed this issue · 3 comments

Currently if you use isNotNil to filter an array of type (T | undefined | null)[], the result will have the same type.

If, instead, we would define isNotNil as follows:

export const isNotNil = <T>(value?: T): value is Exclude<T, null | undefined> => value != null

we could do something like

const example = [1, 23, null, 5, undefined].filter(isNotNil) // typed as `number[]`

ty for posting the issue @lensbart , moving to the types repo

What you're asking for is the current behavior, see here: https://github.com/ramda/types/blob/develop/types/isNotNil.d.ts#L1

Whoops. Not sure what went wrong when I tried it out earlier, but now that I take a second look, this is indeed the current behaviour.

Apologies