paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

Option to disable currying #51

Open JAForbes opened 7 years ago

JAForbes commented 7 years ago

I'm proposing we have an option (similar to Type.check) that disables currying.

If I define a type that requires 3 properties, and I mistakenly only pass in 2, I'd like a type error to occur instead of silently ignoring the problem (by creating a curried type constructor).

It also would mitigate the problem of #45 (hitting a maximum key limit when using curryN).

It would also allow us to get invalid type errors as soon as they are introduced instead of only doing checks at the point of execution.

I think it would be as simple as optionally replacing curry with an identity decorator that just returns the original function instead.

Something like:

const curry = Type.disableCurry ? (n, f) => f : R.curryN

Any thoughts / objections?

I'd also like to propose for removing curried constructors entirely and leaving that as a task for userland. But I realise that proposal would probably break existing code and be less popular.