Given a function:
const f = (a, b, c, d) => { – }
Which has these typings:
type F = (a: number, b: number, c: number, d: number): number
That is curried using Ramda's curry:
import { curry } from 'ramda'
const fc = curry(f)
How should fc
be typed?
Given that there are four params, the function can be called in the following 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 I efficiently provide typings without having to add each 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 I curry a function an don't export it, I don't get any errors, however the moment I export a function I get the following error:
The inferred type of 'fc' cannot be named without a reference to '.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Function/Curry'. This is likely not portable. A type annotation is necessary.
Error TS 2742 only occurs when the compiler is trying to emit type declarations. If you are working on application code (as opposed to library code) there is no need to emit declaration files as they are not used by either the browser or server JS runtimes like node.
Just set "declaration": false
in your tsconfig.json
.