Skip to content

Commit

Permalink
fix(pipeP): first fn should return PromiseLike (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang authored Dec 21, 2017
1 parent dfcadbd commit 3e63e1e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions snapshots/ramda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,8 @@ import * as R from '../ramda/dist/index';
(m: number) => Promise.resolve(m / 2),
R.multiply(5),
)(10);
// @dts-jest:fail:snap -> Argument of type '() => number' is not assignable to parameter of type '(v1: {}, v2: {}, v3: {}, v4: {}, v5: {}, v6: {}) => PromiseLike<{}>'.
R.pipeP(() => 1);
})();

// @dts-jest:group pluck
Expand Down
2 changes: 1 addition & 1 deletion templates/pipeP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default create_composition_declarations(
max_curry_level,
6,
x => x,
x => `PromiseLike<${x}> | ${x}`,
(x, i) => (i === 0 ? `PromiseLike<${x}>` : `PromiseLike<${x}> | ${x}`),
x => `PromiseLike<${x}>`,
);
15 changes: 11 additions & 4 deletions templates/utils/create-composition-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ export const create_composition_declarations = (
// istanbul ignore next
generate_function_parameter_type: (generic: string) => string = x => x,
// istanbul ignore next
generate_function_return_type: (generic: string) => string = x => x,
generate_function_return_type: (
generic: string,
index: number,
) => string = x => x,
// istanbul ignore next
generate_composed_return_type: (
generate_composed_return_type = generate_function_return_type as (
generic: string,
) => string = generate_function_return_type,
) => string,
) => {
const function_names = R.repeat(0, max_function_count).map(
(_, index) => `fn${index + 1}`,
Expand Down Expand Up @@ -81,12 +84,16 @@ export const create_composition_declarations = (
return index === entry_index
? `${function_name}: (${entry_parameters}) => ${generate_function_return_type(
return_generic,
index,
)}`
: `${function_name}: (v: ${generate_function_parameter_type(
current_sorted_return_generics[
index + (kind === 'compose' ? 1 : -1)
],
)}) => ${generate_function_return_type(return_generic)}`;
)}) => ${generate_function_return_type(
return_generic,
index,
)}`;
})
.join(',')}
): (${entry_parameters}) => ${generate_composed_return_type(
Expand Down
5 changes: 5 additions & 0 deletions tests/__snapshots__/ramda-tests.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,11 @@ exports[`pipeP R.pipeP(
(m: number) => Promise.resolve(m / 2),
)(10) 1`] = `"PromiseLike<number>"`;
exports[`pipeP R.pipeP(() => 1) 1`] = `
"Argument of type '() => number' is not assignable to parameter of type '(v1: {}, v2: {}, v3: {}, v4: {}, v5: {}, v6: {}) => PromiseLike<{}>'.
Type 'number' is not assignable to type 'PromiseLike<{}>'."
`;
exports[`pluck R.pluck(
'value',
R.pick(['a'])({
Expand Down
2 changes: 2 additions & 0 deletions tests/ramda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,8 @@ import * as R from '../ramda/dist/index';
(m: number) => Promise.resolve(m / 2),
R.multiply(5),
)(10);
// @dts-jest:fail:snap
R.pipeP(() => 1);
})();

// @dts-jest:group pluck
Expand Down

0 comments on commit 3e63e1e

Please sign in to comment.