-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d2b856
commit 615a8e2
Showing
2 changed files
with
68 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
}); | ||
}); |