4 ms·
The type of a curried function in Typescript is just something like: (a: number) => (b: number) => (c: number) => number Sure, the parameter names and paren
by skishore 9y ago
The type of a curried function in Typescript is just something like:
(a: number) => (b: number) => (c: number) => number
Sure, the parameter names and parentheses are a bit annoying, but I wouldn't call that "very verbose". Comparable concepts in C++ or Java would be a nightmare to type out.
- noshbrinken 9y agoI can't speak to Typescript but check out the Flow types for Ramda: https://github.com/flowtype/flow-typed/blob/master/definitions/npm/ramda_v0.x.x/flow_v0.39.x-/ramda_v0.x.x.js https://github.com/flowtype/flow-typed/blob/master/definitio... Maybe just a matter of perception but it looks verbose to me.
- tommikaikkonen 9y agoI agree, that doesn't look bad. However, this type definition forces you to supply one argument per function call, which looks awful in JavaScript: fn(1)(2)(3) That's a big drawback for me. Libraries like Ramda allow one or more arguments per function call: fn(1, 2, 3) === fn(1, 2)(3) === fn(1)(2, 3) That's what makes the verbosity unbearable, as each type of call needs its own type.
- noppa 9y agoAt least in Flow it's actually possible to properly type curried functions! Here's a gist of the type definitions I'm using: https://gist.github.com/noppa/c600cc43fd44e33768efe6c6eec4a99a https://gist.github.com/noppa/c600cc43fd44e33768efe6c6eec4a9... I think something similar might work in TS too. Demo: https://goo.gl/w3aPsw https://goo.gl/w3aPsw
- kuschku 9y agoWhile Java’s option is quite painful Function<Number, Function<Number, Function<Number, Number>>> The same in Kotlin is actually okayish: (Number) -> (Number) -> (Number) -> Number