Skip to content

Commit

Permalink
convert compose to typescript (reduxjs#3532)
Browse files Browse the repository at this point in the history
Former-commit-id: f15d63e
Former-commit-id: 6b739b8
  • Loading branch information
cellog authored and timdorr committed Aug 29, 2019
1 parent 57cd698 commit 2718f70
Showing 1 changed file with 4 additions and 3 deletions.
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)))
}

0 comments on commit 2718f70

Please sign in to comment.