Skip to content

Commit 3e63e1e

Browse files
authored
fix(pipeP): first fn should return PromiseLike (#363)
1 parent dfcadbd commit 3e63e1e

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

snapshots/ramda-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,8 @@ import * as R from '../ramda/dist/index';
22692269
(m: number) => Promise.resolve(m / 2),
22702270
R.multiply(5),
22712271
)(10);
2272+
// @dts-jest:fail:snap -> Argument of type '() => number' is not assignable to parameter of type '(v1: {}, v2: {}, v3: {}, v4: {}, v5: {}, v6: {}) => PromiseLike<{}>'.
2273+
R.pipeP(() => 1);
22722274
})();
22732275

22742276
// @dts-jest:group pluck

templates/pipeP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export default create_composition_declarations(
77
max_curry_level,
88
6,
99
x => x,
10-
x => `PromiseLike<${x}> | ${x}`,
10+
(x, i) => (i === 0 ? `PromiseLike<${x}>` : `PromiseLike<${x}> | ${x}`),
1111
x => `PromiseLike<${x}>`,
1212
);

templates/utils/create-composition-declarations.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ export const create_composition_declarations = (
99
// istanbul ignore next
1010
generate_function_parameter_type: (generic: string) => string = x => x,
1111
// istanbul ignore next
12-
generate_function_return_type: (generic: string) => string = x => x,
12+
generate_function_return_type: (
13+
generic: string,
14+
index: number,
15+
) => string = x => x,
1316
// istanbul ignore next
14-
generate_composed_return_type: (
17+
generate_composed_return_type = generate_function_return_type as (
1518
generic: string,
16-
) => string = generate_function_return_type,
19+
) => string,
1720
) => {
1821
const function_names = R.repeat(0, max_function_count).map(
1922
(_, index) => `fn${index + 1}`,
@@ -81,12 +84,16 @@ export const create_composition_declarations = (
8184
return index === entry_index
8285
? `${function_name}: (${entry_parameters}) => ${generate_function_return_type(
8386
return_generic,
87+
index,
8488
)}`
8589
: `${function_name}: (v: ${generate_function_parameter_type(
8690
current_sorted_return_generics[
8791
index + (kind === 'compose' ? 1 : -1)
8892
],
89-
)}) => ${generate_function_return_type(return_generic)}`;
93+
)}) => ${generate_function_return_type(
94+
return_generic,
95+
index,
96+
)}`;
9097
})
9198
.join(',')}
9299
): (${entry_parameters}) => ${generate_composed_return_type(

tests/__snapshots__/ramda-tests.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@ exports[`pipeP R.pipeP(
10911091
(m: number) => Promise.resolve(m / 2),
10921092
)(10) 1`] = `"PromiseLike<number>"`;
10931093
1094+
exports[`pipeP R.pipeP(() => 1) 1`] = `
1095+
"Argument of type '() => number' is not assignable to parameter of type '(v1: {}, v2: {}, v3: {}, v4: {}, v5: {}, v6: {}) => PromiseLike<{}>'.
1096+
Type 'number' is not assignable to type 'PromiseLike<{}>'."
1097+
`;
1098+
10941099
exports[`pluck R.pluck(
10951100
'value',
10961101
R.pick(['a'])({

tests/ramda-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,8 @@ import * as R from '../ramda/dist/index';
22692269
(m: number) => Promise.resolve(m / 2),
22702270
R.multiply(5),
22712271
)(10);
2272+
// @dts-jest:fail:snap
2273+
R.pipeP(() => 1);
22722274
})();
22732275

22742276
// @dts-jest:group pluck

0 commit comments

Comments
 (0)