Skip to content

Commit

Permalink
chore@small
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Feb 3, 2025
1 parent 0b658d8 commit 4e3cf57
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
6 changes: 3 additions & 3 deletions source/map-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ describe('R.map with array', () => {
x; // $ExpectType number
return x > 1;
}, list);
result; // $ExpectType number[]
result; // $ExpectType boolean[]
});
it('within piped', () => {
const result = piped(
list,
(x) => x,
map((x) => {
x; // $ExpectType number
return x > 1;
return String(x);
}),
);
result; // $ExpectType number[]
result; // $ExpectType string[]
});
it('within pipe requires explicit type', () => {
pipe(
Expand Down
15 changes: 8 additions & 7 deletions source/mapIndexed-spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {mapIndexed} from 'rambda'
import {mapIndexed, piped} from 'rambda'

const fn = (x: number, i: number) => {
x // $ExpectType number
i // $ExpectType number
return x + 2
}
const list = [1, 2, 3]

describe('R.mapIndexed', () => {
it('happy', () => {
const result = mapIndexed<number>(fn, list)
const result = mapIndexed(fn, list)
result // $ExpectType number[]
})
it('curried', () => {
const result = mapIndexed<number>(fn)(list)
result // $ExpectType number[]
it('inside piped', () => {
const result = piped(
list,
mapIndexed(fn),
)
result // $ExpectType number[]
})
})
16 changes: 8 additions & 8 deletions source/mapObjIndexed-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ describe('R.mapObjIndexed', () => {
const result = mapObjIndexed((x, prop, obj) => {
x // $ExpectType number
prop // $ExpectType string
obj // $ExpectType Dictionary<number>
obj // $ExpectType Record<string, number>
return x + 2
}, obj)
result // $ExpectType Dictionary<number>
result // $ExpectType Record<string, number>
})
it('without type transform - curried', () => {
const result = mapObjIndexed<number, number, string>((x, prop, obj) => {
x // $ExpectType number
prop // $ExpectType string
obj // $ExpectType Dictionary<number>
obj // $ExpectType Record<string, number>
return x + 2
})(obj)
result // $ExpectType Dictionary<number>
result // $ExpectType Record<string, number>
})
it('change of type', () => {
const result = mapObjIndexed((x, prop, obj) => {
x // $ExpectType number
prop // $ExpectType string
obj // $ExpectType Dictionary<number>
obj // $ExpectType Record<string, number>
return String(x + 2)
}, obj)
result // $ExpectType Dictionary<string>
result // $ExpectType Record<string, string>
})
it('change of type - curried', () => {
const result = mapObjIndexed<number, string, string>((x, prop, obj) => {
x // $ExpectType number
prop // $ExpectType string
obj // $ExpectType Dictionary<number>
obj // $ExpectType Record<string, number>
return String(x + 2)
})(obj)
result // $ExpectType Dictionary<string>
result // $ExpectType Record<string, string>
})
})
4 changes: 2 additions & 2 deletions source/mergeWith-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type Output = MergeInsertions<typeof A & typeof B>
describe('R.mergeWith', () => {
test('no curry', () => {
const result = mergeWith<Output>(concat, A, B)
result // $ExpectType Output
result // $ExpectType { a: boolean; values: number[]; b: boolean;}
})
test('inside piped', () => {
const result = piped(
A,
mergeWith<Output>(concat, B),
)
result // $ExpectType Output
result // $ExpectType { a: boolean; values: number[]; b: boolean;}
})
})
18 changes: 6 additions & 12 deletions source/modify-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { add, identity, modify, toUpper } from 'rambda';
import { modify } from 'rambda';

type Obj = {
foo: string;
Expand All @@ -7,17 +7,11 @@ type Obj = {

describe('R.modify', () => {
it('ramda tests', () => {
const result1 = modify('foo', toUpper, {} as Obj);
result1; // $ExpectType Obj
const result1 = modify('foo', Number, {} as Obj);
result1.foo; // $ExpectType number
result1.bar; // $ExpectType number

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

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

modify('bar', toUpper, {} as Obj);
// @ts-expect-error
modify('foo', add(1), {} as Obj);
const result2 = modify('bar', String, {} as Obj);
result2.bar; // $ExpectType string
});
});

0 comments on commit 4e3cf57

Please sign in to comment.