Imagine you have a function defined as follows:
const f = (a, b, c, d) => { – }
This function has the following typings:
type F = (a: number, b: number, c: number, d: number): number
If we curried this function using Ramda's curry, it would look like this:
import { curry } from 'ramda'
const fc = curry(f)
Now, how should the type for fc
be defined?
Considering that the function takes four parameters, it can be called in various ways:
fc(1,1,1,1)
fc(1)(1)(1)(1)
fc(1)(1,1,1)
fc(1)(1,1)(1)
fc(1)(1)(1,1)
fc(1,1)(1)(1)
fc(1,1)(1,1)
fc(1,1,1)(1)
How can the typings be efficiently provided without needing to list each possible variation?
const fc: {
(a: number, b: number, c: number, d: number): number,
(a: number): (b: number): (c: number): (d: number) => number,
(a: number): (b: number) => (c: number) => (d: number): number,
…
} = curry(f)
If a function is curried but not exported, no errors occur. However, when attempting to export the function, the following error may arise:
The inferred type of 'fc' cannot be named without a reference to '.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6612154b1209090a04030a12265f48504856">[email protected]</a>/node_modules/ts-toolbelt/out/Function/Curry'. This is likely not portable. A type annotation is necessary.