Skip to content

fix(adjust): add tuple kind #280

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

Merged
merged 1 commit into from
Oct 10, 2017
Merged

fix(adjust): add tuple kind #280

merged 1 commit into from
Oct 10, 2017

Conversation

ikatyang
Copy link
Member

Fixes #273

This PR adds tuple support for R.adjust, but it's disabled by default since TS may pick wrong kind for list, you have to specify kind manually, e.g. R.adjust<"111", "tuple"> or other types satisfied the tuple kind.

NOTE: the tuple version of R.adjust only supports fn: (x: T) => T, does not support fn: (x: T) => U since AFAIK there's no way to "adjust" a tuple type.

// @dts-jest:pass:snap -> [string, number]
R.adjust<'111', 'tuple'>()(string_to_string, 0, string_number_tuple);
// @dts-jest:fail:snap -> Argument of type 'Morphism<string, string>' is not assignable to parameter of type 'Morphism<number, number>'.
R.adjust<'111', 'tuple'>()(string_to_string, 1, string_number_tuple);
import * as R from 'ramda';

export const mapKeys = R.curry(
- (fn: ???, obj: { [k: string]: any } | { [k: number]: any }) =>
+ (fn: (key: string) => string, obj: { [k: string]: any } | { [k: number]: any }) =>
    R.fromPairs(
      R.map(
-       R.adjust(fn, 0), // <--- Error: tried typings for `adjust`
+       R.adjust<0, [string, any]>(fn, 0),
        R.toPairs(obj) // Fixed by referencing typings of `toPairs`
      )
    )
);

Copy link
Member

@KiaraGrouwstra KiaraGrouwstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK there's no way to "adjust" a tuple type

Yeah, that needs microsoft/TypeScript#17884. Changes LGTM.

@ikatyang ikatyang merged commit a4a4234 into master Oct 10, 2017
@ikatyang ikatyang deleted the fix/issue-273 branch October 10, 2017 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants