Skip to content

Commit

Permalink
feat@fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Apr 1, 2024
1 parent bc535f2 commit c6cdae1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6981,6 +6981,8 @@ Notes:
// @SINGLE_MARKER
export function mapToObject<T, U extends object>(fn: (input: T) => U|false, list: readonly T[]): U;
export function mapToObject<T, U extends object>(fn: (input: T) => U|false): (list: readonly T[]) => U;
export function mapToObject<T, U>(fn: (input: T) => object|false, list: T[]): U;
export function mapToObject<T, U>(fn: (input: T) => object|false): (list: T[]) => U;

/*
Method: mapToObjectAsync
Expand All @@ -7001,6 +7003,8 @@ Notes:
// @SINGLE_MARKER
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>, list: readonly T[]): Promise<U>;
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>): (list: readonly T[]) => Promise<U>;
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<Output[keyof Output]|false>, list: T[]): Promise<U>;
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<Output[keyof Output]|false>): (list: T[]) => Promise<U>;

/*
Method: mapKeys
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions source/mapToObject-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ const fn = (x: number) => {
}

describe('R.mapToObject', () => {
it('happy', () => {
it('when passing explicit types', () => {
const result = mapToObject<number, Output>(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<number, Output>(fn)(list)
result // $ExpectType Output
})
test('curried - when not passing explicit types', () => {
const result = mapToObject(fn)(list)
result // $ExpectType { [x: string]: number; }
})
})
21 changes: 20 additions & 1 deletion source/mapToObjectAsync-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, Output>(fn, list)
result // $ExpectType Output
Expand All @@ -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; }
})
})

0 comments on commit c6cdae1

Please sign in to comment.