ts-curry Currying Utility
ts-curry is a specialized utility library designed for currying functions in TypeScript, providing type-safe currying transformations for functions with up to four arguments. The package's current stable version is 1.0.4, released in July 2018. It has seen no further updates or releases since then, indicating that the project is abandoned. While it offers type safety for currying, its limitation to functions of arity 4 or less, and the lack of maintenance for several years, means it may not be compatible with modern TypeScript versions (e.g., TS 4.x, 5.x) or offer the flexibility of more actively maintained functional programming libraries. Its primary differentiator was its strong TypeScript typing at the time of its release.
Common errors
-
TypeError: (0 , ts_curry_1.curry2) is not a function
cause This error often occurs in modern JavaScript environments (especially Node.js ESM) when trying to `require` or incorrectly import a package that expects `import` syntax or has an incompatible module export structure due to its age.fixEnsure you are using `import { curry2 } from 'ts-curry';` in a TypeScript/ESM context. If you must use CommonJS `require`, ensure your bundler or TypeScript configuration (e.g., `"module": "commonjs", "esModuleInterop": true`) is correctly set up to handle interop with older libraries. -
Argument of type '(a: number, b: Date, c: string, d: boolean, e: any) => any' is not assignable to parameter of type '(a: any, b: any, c: any, d: any) => any'.
cause Attempting to use `curry4` (or `curry2`, `curry3`) with a function that has more arguments than the `curryX` utility is designed to handle.fixThe `ts-curry` library is limited to currying functions of up to 4 arguments. Refactor your function to have 4 or fewer arguments, or choose a different currying library that supports higher arity functions. -
Type 'Date' is not assignable to type 'MyDate'. Property 'getDay' is missing in type 'Date' but required in type 'MyDate'.
cause This is a typical TypeScript error indicating a mismatch between the expected type for a curried function's argument and the actual type provided, often due to specific interfaces being defined in the library's types that are not met by standard built-in types.fixEnsure that the arguments passed to the curried function strictly conform to the expected TypeScript interface defined within `ts-curry`'s types. You might need to cast values or create specific instances that satisfy the type requirements, as shown in the quickstart example (e.g., `new Date() as MyDate`).
Warnings
- breaking The `ts-curry` package is abandoned and has not been updated since July 2018. It is highly likely to have compatibility issues with modern TypeScript versions (e.g., 4.x, 5.x) due to significant language changes and stricter type inference over the years, potentially leading to incorrect or broken type definitions.
- gotcha The library explicitly supports currying only up to functions with an arity of 4 (via `curry2`, `curry3`, `curry4`). Attempting to curry functions with more than 4 arguments using these utilities will result in compile-time type errors or runtime unexpected behavior, as there are no higher-arity `curry` functions provided.
- gotcha Due to its age, `ts-curry` likely targets older versions of JavaScript and module systems. While it uses `import` syntax, its underlying CommonJS output or type definitions might cause issues when consumed in modern ESM-only Node.js environments or complex bundler setups, leading to module resolution errors.
Install
-
npm install ts-curry -
yarn add ts-curry -
pnpm add ts-curry
Imports
- curry2
const { curry2 } = require('ts-curry');import { curry2 } from 'ts-curry'; - curry3
import { curry3 } from 'ts-curry'; - curry4
import { curry4 } from 'ts-curry';
Quickstart
import { curry2 } from 'ts-curry';
interface MyDate extends Date {
getDay(): number;
}
// Define a function with explicit types
const func = (a: number, b: MyDate): number => a + b.getDay();
// Curry the function using curry2
const curried = curry2(func);
// Call the curried function with all arguments at once
const date1: MyDate = new Date('2026-04-19T10:00:00Z') as MyDate; // Example date for consistent output
console.log('Result (all args):', curried(2, date1));
// Call the curried function step-by-step
const partialCurried = curried(2);
const date2: MyDate = new Date('2026-04-20T10:00:00Z') as MyDate; // Another example date
console.log('Result (curried):', partialCurried(date2));
// Type checking ensures correctness (this would error if types mismatch)
// const wrongType = curried('hello', new Date()); // Would cause TypeScript error