typed-typings / npm-ramda

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

pathOr requires two generics, when one makes more sense #416

Closed ipanasenko closed 6 years ago

ipanasenko commented 6 years ago

Hey guys.

I'm using pathOr like this:

type TSomeProp = { cc: number; };
type TItem = {
  aaa: TSomeProp[];
};
const item: TItem = {
  ...
};

pathOr<TSomeProp[], TSomeProp[]>([], ['aaa'], item);

It seems that I always need to specify two generics, even if I want default to be the same type as what I get on that path.

Do you think we can make second generic optional?

BTW, I think this also applies to propOr

ikatyang commented 6 years ago

Unfortunately, it'll cause an unexpected inference for currying due to their type parameter dependencies:

-R.pathOr('N/A')(['a', 'b'], { a: { b: 2 } }) //=> string | {}
+R.pathOr('N/A')(['a', 'b'], { a: { b: 2 } }) //=> string
ipanasenko commented 6 years ago

Got you, thanks!