From c6cdae1834685d386b19244a7756d22d12cf8505 Mon Sep 17 00:00:00 2001 From: Deyan Totev Date: Mon, 1 Apr 2024 17:22:46 +0300 Subject: [PATCH] feat@fix --- files/index.d.ts | 4 ++++ package.json | 1 + source/mapToObject-spec.ts | 12 ++++++++++-- source/mapToObjectAsync-spec.ts | 21 ++++++++++++++++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/files/index.d.ts b/files/index.d.ts index f55c53d17..1f7a6e7c2 100644 --- a/files/index.d.ts +++ b/files/index.d.ts @@ -6981,6 +6981,8 @@ Notes: // @SINGLE_MARKER export function mapToObject(fn: (input: T) => U|false, list: readonly T[]): U; export function mapToObject(fn: (input: T) => U|false): (list: readonly T[]) => U; +export function mapToObject(fn: (input: T) => object|false, list: T[]): U; +export function mapToObject(fn: (input: T) => object|false): (list: T[]) => U; /* Method: mapToObjectAsync @@ -7001,6 +7003,8 @@ Notes: // @SINGLE_MARKER export function mapToObjectAsync(fn: (input: T) => Promise, list: readonly T[]): Promise; export function mapToObjectAsync(fn: (input: T) => Promise): (list: readonly T[]) => Promise; +export function mapToObjectAsync(fn: (input: T) => Promise, list: T[]): Promise; +export function mapToObjectAsync(fn: (input: T) => Promise): (list: T[]) => Promise; /* Method: mapKeys diff --git a/package.json b/package.json index 9309d08a1..56bfeb9df 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "test:all": "jest source/*.spec.js -u --bail=false", "test:ci": "jest source/*.spec.js --coverage --no-cache -w 1", "test:typings": "dtslint --localTs ./node_modules/typescript/lib --expectOnly ./source", + "test:ts": "yarn test:typings", "ts": "yarn test:typings", "usedby": "cd ../rambda-scripts && yarn usedby", "x": "yarn populatedocs:x && yarn populatereadme:x && yarn immutable:x" diff --git a/source/mapToObject-spec.ts b/source/mapToObject-spec.ts index a8e91af9f..f08ac7fb7 100644 --- a/source/mapToObject-spec.ts +++ b/source/mapToObject-spec.ts @@ -14,12 +14,20 @@ const fn = (x: number) => { } describe('R.mapToObject', () => { - it('happy', () => { + it('when passing explicit types', () => { const result = mapToObject(fn, list) result // $ExpectType Output }) - it('curried', () => { + test('when not passing explicit types', () => { + const result = mapToObject(fn, list) + result // $ExpectType { [x: string]: number; } + }) + it('curried - when passing explicit types', () => { const result = mapToObject(fn)(list) result // $ExpectType Output }) + test('curried - when not passing explicit types', () => { + const result = mapToObject(fn)(list) + result // $ExpectType { [x: string]: number; } + }) }) diff --git a/source/mapToObjectAsync-spec.ts b/source/mapToObjectAsync-spec.ts index 118ee94bc..553725ac3 100644 --- a/source/mapToObjectAsync-spec.ts +++ b/source/mapToObjectAsync-spec.ts @@ -13,7 +13,7 @@ const fn = async(x: number) => { return x % 2 ? {[`key${x}`]: x + 1} : {[`key${x}`]: x + 10} } -describe('R.mapToObjectAsync', () => { +describe('R.mapToObjectAsync - explicit output types', () => { it('happy', async() => { const result = await mapToObjectAsync(fn, list) result // $ExpectType Output @@ -31,3 +31,22 @@ describe('R.mapToObjectAsync', () => { result // $ExpectType Output }) }) + +describe('R.mapToObjectAsync - implicit output types', () => { + it('happy', async() => { + const result = await mapToObjectAsync(fn, list) + result // $ExpectType { [x: string]: number; } + }) + it('curried', async() => { + const result = await mapToObjectAsync(fn)(list) + result // $ExpectType { [x: string]: number; } + }) + it('with R.composeAsync', async() => { + const result = await composeAsync( + mapToObjectAsync(fn), + (x: number[]) => x.filter((xx: number) => xx > 2) + )(list) + + result // $ExpectType { [x: string]: number; } + }) +})