I have been self-learning TypeScript via the TS docs. While reading a section that I posted below, (in text form, as well as the link), I came across a word I haven't heard before ARITY. Usually I just search the TS docs to find out what some specific syntax means, but I am guessing this isn't TypeScript, because the docs didn't return any specific definition for 'Arity' in the search Results. As stated above, below is the documentation I came across, that uses 'Arity'. The documentation relies on heavily on the definition of 'arity', and I couldn't find anyone defining it here on stackoverflow, or in a DDG search. If anyone could define this for me that would be awesome.
Below is the TypeScript Documentation that I found 'arity' in, and am trying to understand.
Overloads and Callbacks #
❌ Don’t write separate overloads that differ only on callback arity:
/* WRONG */ declare function beforeAll(action: () => void, timeout?: number): void; declare function beforeAll( action: (done: DoneFn) => void, timeout?: number ): void;
✅ Do write a single overload using the maximum arity:
/* OK */ declare function beforeAll( action: (done: DoneFn) => void, timeout?: number ): void;
❔ Why: It’s always legal for a callback to disregard a parameter, so there’s no need for the shorter overload. Providing a shorter callback first allows incorrectly-typed functions to be passed in because they match the first overload.