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

Question: compose and assoc to build a structure #101

Closed
xeob opened this issue Oct 20, 2016 · 5 comments
Closed

Question: compose and assoc to build a structure #101

xeob opened this issue Oct 20, 2016 · 5 comments

Comments

@xeob
Copy link

xeob commented Oct 20, 2016

Hi folks, this is a question rather than an issue. I'm somewhat new to the wonders of ramda and TypeScript and I might have a naive question here, so please bear with me 😉

I'm trying to build an object that matches a given interface through compose and mutliple assocs, something like

interface SomeStruct {
  a: number[];
  b: string[];
  c: { [index: string]: string };
}

const x: SomeStruct = {
  'a': [],
  'b': [],
  'c': {},
};

const fun = (y: SomeStruct): SomeStruct => {
  return compose(
    assoc('a', [1, 2, 3]),
    assoc('b', ['a', 'b', 'c']),
    assoc('c', { 'k': 'v'})
  )(y);
};

fun(x);

Doing this, I'm getting a following error:

error TS2322: Type '{ prop: number[]; } & {}' is not assignable to type 'SomeStruct'.
Property 'a' is missing in type '{ prop: number[]; } & {}'

The effective and intermediate structure of x matches the SomeType at all steps of this function application. Is there some way around it besides using as any after compose? Am I missing something pretty basic here?


Edit: Sorry, now I see it might be related to #90

@wclr
Copy link
Contributor

wclr commented Nov 4, 2016

{ prop: number[]; } is wrong, assoc has really not working typings, should be fixed.

@KiaraGrouwstra
Copy link
Member

If this turns out not be a duplicate when #90 is resolved, let's reopen.

@KiaraGrouwstra
Copy link
Member

So I fixed #90; guess what, your test isn't passing yet. So reopening until your test passes, as promised. :)

@KiaraGrouwstra
Copy link
Member

Well, now we know. This wasn't an assoc issue, but a composition one.

It stems from interaction between composition and functions with generics. Threads #92 and #86 appeared to be about the same problem. I currently intend to track this issue in #78, about currying rather than composition but otherwise seemingly the same issue.

Sorry you're getting bounced to yet another thread again. I'm slowly discovering most outstanding issues are highly related though, so hopefully if I can figure this out we'll have solved everything in one go.

@xeob
Copy link
Author

xeob commented Dec 11, 2016

No worries @tycho01. Thanks a lot for the time you've put into looking into that!

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