typed-typings / npm-ramda

TypeScript's type definitions for Ramda
MIT License
384 stars 64 forks source link

equals doesn't work as expected for undefined and null #383

Closed frankpf closed 6 years ago

frankpf commented 6 years ago

I'm trying to check if an array has an undefined value using any(equals(undefined)):

import { any, equals } from 'ramda'

const test = any(equals(undefined), [1, 2, 3, 4, undefined])

The issue is that the type of equals is equals<T>(a: T, b: T): boolean. The type makes sense for all parameters other than null and undefined.

To type check correctly in this case, I have to parametrize it to equals<number | undefined>. This works, but it is a bit inconvenient.

This probably could be resolved by adding two function overloads:

equals<T>(a: undefined, b: T | undefined): boolean;
equals<T>(a: null, b: T | null): boolean;
KiaraGrouwstra commented 6 years ago

Sounds fair! Might be we still had some similar (T, T) types (other comparison functions?) still suffering from this as well.