question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ramda] Why does dissoc uses a generic ?

See original GitHub issue

Actual definition is :

declare function dissoc<T>(
    key: string,
    ...args: Array<void>
  ): (src: { [k: string]: T }) => { [k: string]: T };
declare function dissoc<T>(
    key: string,
    src: { [k: string]: T }
): { [k: string]: T };

I don’t get why we want to enforce a unique type T a object content ?

I have a union use case where this causes trouble :

// @flow
import * as R from 'ramda'

type OtherType = { toto: string }

export type ActionA = {|
  type: string,
  payload: {| somePayload: string |}
|}

export type ActionB = {|
  type: string,
  payload: {| someOtherPayload: OtherType |}
|}

export type Action = ActionA | ActionB

const filterAction = (a: Action): {} => R.dissoc('type')(a)

I don’t see why Flow errors, and I don’t see any problem with this code …

When I change libdef to the following, I don’t have any problem :

declare function dissoc(
    key: string
  ): (src: { [k: string]: any }) => { [k: string]: any };
  declare function dissoc(
    key: string,
    src: { [k: string]: any }
  ): { [k: string]: any };

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:25 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
LoganBarnettcommented, Nov 26, 2018

Don’t we want (obj1.a: number | string | boolean) to fail because a is not on obj1, and (obj1.b: number | string | boolean) to fail because it is a string?

0reactions
AndrewSouthpawcommented, Dec 19, 2018

Oops, you’re quite right, I had missed that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ramda Documentation
(This latter might be unimportant if the list parameter is not used.) Open in REPL ... Run it here. R.dissoc('b', {a: 1, b:...
Read more >
Typescript typing issue #2487 - ramda/ramda - GitHub
Should we ensure that all Ramda functions can be used with Elm, ... export function dissoc (...rest: any[]): any; export function dissocPath ...
Read more >
ramda/ramda - Gitter
Hi everyone, I'm new to Ramda (and FP) and was hoping for some help with ... two functions, with difference in using assoc...
Read more >
Thinking in Ramda: Immutability and Arrays - Randy Coulman
Ramda has even more methods for reading array elements. ... For objects, we learned about assoc , dissoc , and omit for adding,...
Read more >
Use Ramda.js to pull off items from object - Stack Overflow
Lenses are probably your best bet for this. Ramda has a generic lens function, and specific ones for an object property ( lensProp...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found