Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert compose to typescript #3532

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/compose.js → src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
* (...args) => f(g(h(...args))).
*/

export default function compose(...funcs) {
export default function compose(...funcs: Function[]) {
if (funcs.length === 0) {
return arg => arg
// infer the argument type so it is usable in inference down the line
return <T>(arg: T) => arg
}

if (funcs.length === 1) {
return funcs[0]
}

return funcs.reduce((a, b) => (...args) => a(b(...args)))
return funcs.reduce((a, b) => (...args: any) => a(b(...args)))
}