Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R.merge is not compatible with interfaces #136

Closed
sluukkonen opened this issue Feb 9, 2017 · 3 comments
Closed

R.merge is not compatible with interfaces #136

sluukkonen opened this issue Feb 9, 2017 · 3 comments

Comments

@sluukkonen
Copy link

This code

import * as R from 'ramda'

interface User {
  readonly name: string
  readonly age: number
}

const u1: User = {name: 'John', age: 25}
const u2: User = {name: 'Jane', age: 25}

const u3 = R.merge(u1, u2)

produces the following error:

Argument of type 'User' is not assignable to parameter of type 'Struct<{}>'.
  Type 'User' is not assignable to type 'ArrayLike<{}>'.
    Property 'length' is missing in type 'User'

I'm not quite sure what's wrong with the "obvious" signature (merge<T1, T2>(a: T1, b: T2): T1 & T2), but the current one is definitely problematic.

@KiaraGrouwstra
Copy link
Member

Yeah, this is a variant of our biggest problem right now (e.g. #78), caused by the state of TS; progress for a solution can be found here.

@wclr
Copy link
Contributor

wclr commented Apr 2, 2017

  1. What is really wrong with a signature in case of merge?
    merge<T1, T2>(a: T1, b: T2): T1 & T2;?

  2. Or why not, if want to introduce constraints that it is a structure:
    merge<T1 extends Struct<any> , T2 extends Struct<any>>(a: T1, b: T2): T1 & T2;

  3. Why type Struct<T> = Obj<T> | List<T>; is used when ramda's merge actually expects objects (Obj)?

@KiaraGrouwstra
Copy link
Member

Sorry, you're right this signature contained more generics than it could really put to good use.

I guess technically Ramda also accepts the use-case of merging arrays, though I'll admit it's a bit unexpected there it's still going to treat everything as objects anyway:

R.merge([1],[2,3]);
Object {0: 2, 1: 3}

My initial instinct has been to not immediately prohibit use-cases that could technically be legitimate. That said, I'll admit I haven't actually used this array version here myself either...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants