Subtract
约 130 字小于 1 分钟
2026-02-11
题目
Implement the type Subtraction that is - in Javascript by using BuildTuple.
If the minuend is less than the subtrahend, it should be never.
It's a simple version.
For example
Subtract<2, 1> // expect to be 1
Subtract<1, 2> // expect to be never解题思路
待补充
答案
// M => minuend, S => subtrahend
type Subtract<M extends number, S extends number> = any验证
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Subtract<1, 1>, 0>>,
Expect<Equal<Subtract<2, 1>, 1>>,
Expect<Equal<Subtract<1, 2>, never>>,
// @ts-expect-error
Expect<Equal<Subtract<1000, 999>, 1>>,
]参考
无
