Skip to content

Commit

Permalink
feat@fix modify
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Aug 18, 2024
1 parent 2d2b856 commit 615a8e2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 39 deletions.
48 changes: 24 additions & 24 deletions source/dissoc-spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import {dissoc} from 'rambda'
import { dissoc } from 'rambda';

type Obj = {
str: string;
num: number;
opt?: boolean;
orUndefined: boolean | undefined;
orNull: boolean | null;
str: string;
num: number;
opt?: boolean;
orUndefined: boolean | undefined;
orNull: boolean | null;
};

const obj: Obj = { str: 'foo', num: 1, orUndefined: true, orNull: true };

describe('R.dissoc', () => {
it('ramda tests', () => {
// @ts-expect-error
dissoc('str', obj)
// @ts-expect-error
dissoc('num', obj)
// @ts-expect-error
dissoc('orNull', obj)
let result1 = dissoc('opt', obj)
result1 // $ExpectType Obj
// @ts-expect-error
dissoc('num')(obj)
let result2 = dissoc('orUndefined', obj)
result2 // $ExpectType Obj
let result3 = dissoc('opt')(obj)
result3 // $ExpectType Obj
})
})
it('ramda tests', () => {
// @ts-expect-error
dissoc('str', obj);
// @ts-expect-error
dissoc('num', obj);
// @ts-expect-error
dissoc('orNull', obj);

const result1 = dissoc('opt', obj);
result1; // $ExpectType Obj
// @ts-expect-error
dissoc('num')(obj);
const result2 = dissoc('orUndefined', obj);
result2; // $ExpectType Obj
const result3 = dissoc('opt')(obj);
result3; // $ExpectType Obj
});
});
59 changes: 44 additions & 15 deletions source/modify-spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
import {modify, add} from 'rambda'
const person = {name: 'James', age: 20}
import { add, identity, map, modify, pipe, toUpper } from 'rambda';

type Obj = {
foo: string;
bar: number;
};

describe('R.modify', () => {
it('happy', () => {
const {age} = modify('age', add(1), person)
const {age: ageAsString} = modify('age', String, person)

age // $ExpectType number
ageAsString // $ExpectType string
})
it('curried', () => {
const {age} = modify('age', add(1))(person)

age // $ExpectType number
})
})
it('ramda tests', () => {
const result1 = modify('foo', toUpper, {} as Obj);
result1; // $ExpectType Obj

const result2 = modify('bar', add(1), {} as Obj);
result2; // $ExpectType Obj

const result3 = modify('foo', toUpper)({} as Obj);
result3; // $ExpectType Obj

const result4 = modify('bar', add(1))({} as Obj);
result4; // $ExpectType Obj

const result5 = modify('foo')(toUpper)({} as Obj);
result5; // $ExpectType Obj

const result6 = modify('bar')(add(1))({} as Obj);
result6; // $ExpectType Obj

const result7 = modify('foo')(toUpper, {} as Obj);
result7; // $ExpectType Obj

const result8 = modify('bar')(add(1), {} as Obj);
result8; // $ExpectType Obj

const result9 = modify('foo', identity, {} as Obj);
result9; // $ExpectType Obj

// @ts-expect-error
modify('foo', add(1), {} as Obj);
// @ts-expect-error
modify('bar', toUpper, {} as Obj);

const f = pipe(map<Obj, Obj>(modify('foo', toUpper)));

f([] as Obj[]); // $ExpectType Obj[]
});
});

0 comments on commit 615a8e2

Please sign in to comment.