remeda
Version:
A utility library for JavaScript and Typescript.
16 lines (14 loc) • 781 B
TypeScript
/**
* We built our own version of Subtract instead of using type-fest's one
* because we needed a simpler implementation that isn't as prone to excessive
* recursion issues and that is clamped at 0 so that we don't need to handle
* negative values using even more utilities.
*/
type ClampedIntegerSubtract<Minuend, Subtrahend, SubtrahendBag extends Array<unknown> = [], ResultBag extends Array<unknown> = []> = [...SubtrahendBag, ...ResultBag]["length"] extends Minuend ? ResultBag["length"] : SubtrahendBag["length"] extends Subtrahend ? ClampedIntegerSubtract<Minuend, Subtrahend, SubtrahendBag, [
...ResultBag,
unknown
]> : ClampedIntegerSubtract<Minuend, Subtrahend, [
...SubtrahendBag,
unknown
], ResultBag>;
export type { ClampedIntegerSubtract as C };