Skip to content

Commit 1242565

Browse files
authored
10.3.3 Fix wrong typing for R.reject (#795)
* chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * Fix R.includes * chore@small * d * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * kata * 2 * 3 * chore@small * chore@small
1 parent 31bfc80 commit 1242565

File tree

13 files changed

+472
-482
lines changed

13 files changed

+472
-482
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
node-version: [ '22', '23' ]
11+
node-version: [ '22', '24' ]
1212

1313
steps:
1414
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
10.3.1
1+
10.3.3
2+
3+
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
4+
5+
- Improve `R.pick` to not allow non-existing keys as input.
6+
7+
10.3.2
28

39
- Fix issue with wrong order of inputs in `R.createObjectFromKeys` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
410

README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5885,7 +5885,7 @@ describe('R.lastIndexOf', () => {
58855885
```typescript
58865886

58875887
map<T extends IterableContainer, U>(
5888-
fn: (value: T[number], index: number) => U,
5888+
fn: (value: T[number], index: number) => U,
58895889
): (data: T) => Mapped<T, U>
58905890
```
58915891
@@ -5911,21 +5911,11 @@ const result = R.map(fn)(iterable),
59115911
59125912
```typescript
59135913
map<T extends IterableContainer, U>(
5914-
fn: (value: T[number], index: number) => U,
5914+
fn: (value: T[number], index: number) => U,
59155915
): (data: T) => Mapped<T, U>;
59165916
map<T extends IterableContainer, U>(
5917-
fn: (value: T[number]) => U,
5917+
fn: (value: T[number]) => U,
59185918
): (data: T) => Mapped<T, U>;
5919-
map<T extends IterableContainer, U>(
5920-
fn: (value: T[number], index: number) => U,
5921-
data: T
5922-
) : Mapped<T, U>;
5923-
map<T extends IterableContainer, U>(
5924-
fn: (value: T[number]) => U,
5925-
data: T
5926-
) : Mapped<T, U>;
5927-
...
5928-
...
59295919
```
59305920
59315921
</details>
@@ -5979,7 +5969,7 @@ import { map, pipe } from 'rambda'
59795969

59805970
const list = [1, 2, 3]
59815971

5982-
it('R.map', () => {
5972+
it('R.map - within pipe', () => {
59835973
const result = pipe(
59845974
list,
59855975
x => x,
@@ -5990,6 +5980,20 @@ it('R.map', () => {
59905980
)
59915981
result // $ExpectType string[]
59925982
})
5983+
5984+
it('R.map - without pipe', () => {
5985+
map(x => {
5986+
x // $ExpectType unknown
5987+
})([1, 2, 3])
5988+
})
5989+
5990+
it('R.map - without pipe but explicitly typed', () => {
5991+
const result = map<number[], string>(x => {
5992+
x // $ExpectType number
5993+
return String(x)
5994+
})([1, 2, 3])
5995+
result // $ExpectType string[]
5996+
})
59935997
```
59945998
59955999
</details>
@@ -8435,7 +8439,7 @@ export function permutations(inputArray) {
84358439
84368440
```typescript
84378441

8438-
pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>
8442+
pick<K extends PropertyKey>(propsToPick: K[]): <T extends Partial<Record<K, any>>>(input: K extends keyof T ? T : never) => MergeTypes<Pick<T, K>>
84398443
```
84408444
84418445
It returns a partial copy of an `input` containing only `propsToPick` properties.
@@ -8478,8 +8482,8 @@ const expected = [
84788482
<summary>All TypeScript definitions</summary>
84798483
84808484
```typescript
8481-
pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>;
8482-
pick<S extends string>(propsToPick: S): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, ElementOf<PickStringToPickPath<S>>>>>>;
8485+
pick<K extends PropertyKey>(propsToPick: K[]): <T extends Partial<Record<K, any>>>(input: K extends keyof T ? T : never) => MergeTypes<Pick<T, K>>;
8486+
pick<S extends string, Keys extends PickStringToPickPath<S>>(propsToPick: S): <T extends Partial<Record<ElementOf<Keys>, any>>>(input: ElementOf<Keys> extends keyof T ? T : never) => ElementOf<Keys> extends keyof T ? MergeTypes<Pick<T, ElementOf<Keys>>> : never;
84838487
```
84848488
84858489
</details>
@@ -8567,15 +8571,19 @@ const input = { a: 'foo', c: 3 }
85678571

85688572
describe('R.pick', () => {
85698573
it('with string as input', () => {
8570-
const result = pipe(input, pick('a,c,b,o'))
8574+
const result = pipe(input, pick('a,c'))
85718575
result.a // $ExpectType string
85728576
result.c // $ExpectType number
85738577
})
85748578
it('with array as input', () => {
8575-
const result = pipe(input, pick(['a', 'c']))
8579+
const result = pipe(input, pick(['a', 'c']))
85768580
result.a // $ExpectType string
85778581
result.c // $ExpectType number
85788582
})
8583+
it('throws error if some keys do not exist', () => {
8584+
// @ts-expect-error
8585+
pipe(input, pick('a,c,b,o'))
8586+
})
85798587
})
85808588
```
85818589
@@ -9790,9 +9798,8 @@ it('R.reduce', () => {
97909798
```typescript
97919799

97929800
reject<T>(
9793-
predicate: (value: T) => boolean,
9794-
list: T[],
9795-
): T[]
9801+
predicate: BooleanConstructor,
9802+
): (list: readonly T[]) => ("" | null | undefined | false | 0)[]
97969803
```
97979804
97989805
It has the opposite effect of `R.filter`.
@@ -9816,10 +9823,6 @@ const result = [
98169823
<summary>All TypeScript definitions</summary>
98179824
98189825
```typescript
9819-
reject<T>(
9820-
predicate: (value: T) => boolean,
9821-
list: T[],
9822-
): T[];
98239826
reject<T>(
98249827
predicate: BooleanConstructor,
98259828
): (list: readonly T[]) => ("" | null | undefined | false | 0)[];
@@ -9829,8 +9832,6 @@ reject<T>(
98299832
reject<T>(
98309833
predicate: (value: T) => boolean,
98319834
): (list: T[]) => T[];
9832-
...
9833-
...
98349835
```
98359836
98369837
</details>
@@ -13541,7 +13542,13 @@ describe('R.zipWith', () => {
1354113542
1354213543
## ❯ CHANGELOG
1354313544
13544-
10.3.1
13545+
10.3.3
13546+
13547+
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
13548+
13549+
- Improve `R.pick` to not allow non-existing keys as input.
13550+
13551+
10.3.2
1354513552
1354613553
- Fix issue with wrong order of inputs in `R.createObjectFromKeys` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
1354713554

docs/README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5885,7 +5885,7 @@ describe('R.lastIndexOf', () => {
58855885
```typescript
58865886

58875887
map<T extends IterableContainer, U>(
5888-
fn: (value: T[number], index: number) => U,
5888+
fn: (value: T[number], index: number) => U,
58895889
): (data: T) => Mapped<T, U>
58905890
```
58915891
@@ -5911,21 +5911,11 @@ const result = R.map(fn)(iterable),
59115911
59125912
```typescript
59135913
map<T extends IterableContainer, U>(
5914-
fn: (value: T[number], index: number) => U,
5914+
fn: (value: T[number], index: number) => U,
59155915
): (data: T) => Mapped<T, U>;
59165916
map<T extends IterableContainer, U>(
5917-
fn: (value: T[number]) => U,
5917+
fn: (value: T[number]) => U,
59185918
): (data: T) => Mapped<T, U>;
5919-
map<T extends IterableContainer, U>(
5920-
fn: (value: T[number], index: number) => U,
5921-
data: T
5922-
) : Mapped<T, U>;
5923-
map<T extends IterableContainer, U>(
5924-
fn: (value: T[number]) => U,
5925-
data: T
5926-
) : Mapped<T, U>;
5927-
...
5928-
...
59295919
```
59305920
59315921
</details>
@@ -5979,7 +5969,7 @@ import { map, pipe } from 'rambda'
59795969

59805970
const list = [1, 2, 3]
59815971

5982-
it('R.map', () => {
5972+
it('R.map - within pipe', () => {
59835973
const result = pipe(
59845974
list,
59855975
x => x,
@@ -5990,6 +5980,20 @@ it('R.map', () => {
59905980
)
59915981
result // $ExpectType string[]
59925982
})
5983+
5984+
it('R.map - without pipe', () => {
5985+
map(x => {
5986+
x // $ExpectType unknown
5987+
})([1, 2, 3])
5988+
})
5989+
5990+
it('R.map - without pipe but explicitly typed', () => {
5991+
const result = map<number[], string>(x => {
5992+
x // $ExpectType number
5993+
return String(x)
5994+
})([1, 2, 3])
5995+
result // $ExpectType string[]
5996+
})
59935997
```
59945998
59955999
</details>
@@ -8435,7 +8439,7 @@ export function permutations(inputArray) {
84358439
84368440
```typescript
84378441

8438-
pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>
8442+
pick<K extends PropertyKey>(propsToPick: K[]): <T extends Partial<Record<K, any>>>(input: K extends keyof T ? T : never) => MergeTypes<Pick<T, K>>
84398443
```
84408444
84418445
It returns a partial copy of an `input` containing only `propsToPick` properties.
@@ -8478,8 +8482,8 @@ const expected = [
84788482
<summary>All TypeScript definitions</summary>
84798483
84808484
```typescript
8481-
pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>;
8482-
pick<S extends string>(propsToPick: S): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, ElementOf<PickStringToPickPath<S>>>>>>;
8485+
pick<K extends PropertyKey>(propsToPick: K[]): <T extends Partial<Record<K, any>>>(input: K extends keyof T ? T : never) => MergeTypes<Pick<T, K>>;
8486+
pick<S extends string, Keys extends PickStringToPickPath<S>>(propsToPick: S): <T extends Partial<Record<ElementOf<Keys>, any>>>(input: ElementOf<Keys> extends keyof T ? T : never) => ElementOf<Keys> extends keyof T ? MergeTypes<Pick<T, ElementOf<Keys>>> : never;
84838487
```
84848488
84858489
</details>
@@ -8567,15 +8571,19 @@ const input = { a: 'foo', c: 3 }
85678571

85688572
describe('R.pick', () => {
85698573
it('with string as input', () => {
8570-
const result = pipe(input, pick('a,c,b,o'))
8574+
const result = pipe(input, pick('a,c'))
85718575
result.a // $ExpectType string
85728576
result.c // $ExpectType number
85738577
})
85748578
it('with array as input', () => {
8575-
const result = pipe(input, pick(['a', 'c']))
8579+
const result = pipe(input, pick(['a', 'c']))
85768580
result.a // $ExpectType string
85778581
result.c // $ExpectType number
85788582
})
8583+
it('throws error if some keys do not exist', () => {
8584+
// @ts-expect-error
8585+
pipe(input, pick('a,c,b,o'))
8586+
})
85798587
})
85808588
```
85818589
@@ -9790,9 +9798,8 @@ it('R.reduce', () => {
97909798
```typescript
97919799

97929800
reject<T>(
9793-
predicate: (value: T) => boolean,
9794-
list: T[],
9795-
): T[]
9801+
predicate: BooleanConstructor,
9802+
): (list: readonly T[]) => ("" | null | undefined | false | 0)[]
97969803
```
97979804
97989805
It has the opposite effect of `R.filter`.
@@ -9816,10 +9823,6 @@ const result = [
98169823
<summary>All TypeScript definitions</summary>
98179824
98189825
```typescript
9819-
reject<T>(
9820-
predicate: (value: T) => boolean,
9821-
list: T[],
9822-
): T[];
98239826
reject<T>(
98249827
predicate: BooleanConstructor,
98259828
): (list: readonly T[]) => ("" | null | undefined | false | 0)[];
@@ -9829,8 +9832,6 @@ reject<T>(
98299832
reject<T>(
98309833
predicate: (value: T) => boolean,
98319834
): (list: T[]) => T[];
9832-
...
9833-
...
98349835
```
98359836
98369837
</details>
@@ -13541,7 +13542,13 @@ describe('R.zipWith', () => {
1354113542
1354213543
## ❯ CHANGELOG
1354313544
13544-
10.3.1
13545+
10.3.3
13546+
13547+
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
13548+
13549+
- Improve `R.pick` to not allow non-existing keys as input.
13550+
13551+
10.3.2
1354513552
1354613553
- Fix issue with wrong order of inputs in `R.createObjectFromKeys` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
1354713554

files/index.d.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -986,19 +986,11 @@ Notes: This function doesn't work with objects (use R.mapObject instead)
986986
*/
987987
// @SINGLE_MARKER
988988
export function map<T extends IterableContainer, U>(
989-
fn: (value: T[number], index: number) => U,
989+
fn: (value: T[number], index: number) => U,
990990
): (data: T) => Mapped<T, U>;
991991
export function map<T extends IterableContainer, U>(
992-
fn: (value: T[number]) => U,
992+
fn: (value: T[number]) => U,
993993
): (data: T) => Mapped<T, U>;
994-
export function map<T extends IterableContainer, U>(
995-
fn: (value: T[number], index: number) => U,
996-
data: T
997-
) : Mapped<T, U>;
998-
export function map<T extends IterableContainer, U>(
999-
fn: (value: T[number]) => U,
1000-
data: T
1001-
) : Mapped<T, U>;
1002994

1003995
/*
1004996
Method: mapObject
@@ -1886,8 +1878,8 @@ Categories: Object
18861878
Notes: pipe
18871879
*/
18881880
// @SINGLE_MARKER
1889-
export function pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>;
1890-
export function pick<S extends string>(propsToPick: S): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, ElementOf<PickStringToPickPath<S>>>>>>;
1881+
export function pick<K extends PropertyKey>(propsToPick: K[]): <T extends Partial<Record<K, any>>>(input: K extends keyof T ? T : never) => MergeTypes<Pick<T, K>>;
1882+
export function pick<S extends string, Keys extends PickStringToPickPath<S>>(propsToPick: S): <T extends Partial<Record<ElementOf<Keys>, any>>>(input: ElementOf<Keys> extends keyof T ? T : never) => ElementOf<Keys> extends keyof T ? MergeTypes<Pick<T, ElementOf<Keys>>> : never;
18911883

18921884
/*
18931885
Method: pipe
@@ -2393,10 +2385,6 @@ Notes:
23932385
23942386
*/
23952387
// @SINGLE_MARKER
2396-
export function reject<T>(
2397-
predicate: (value: T) => boolean,
2398-
list: T[],
2399-
): T[];
24002388
export function reject<T>(
24012389
predicate: BooleanConstructor,
24022390
): (list: readonly T[]) => ("" | null | undefined | false | 0)[];

0 commit comments

Comments
 (0)