Type alias Plus<n1, n2, TargetType>

Plus<n1, n2, TargetType>: PlusPositionStrNum<Str<n1>, Str<n2>> extends `${infer R extends TargetType}`
    ? R
    : never

加法运算,只支持正数。 我目前没有看到负数带来的实际场景作用,而且支持负数的运算会导致一定的性能损耗,加法作为一个基础性工具需要重点考虑性能问题。 当然如果你看到了负数的实际场景作用那么可以向我反馈,我会重新实现支持负数的加法运算。

Type Parameters

  • n1 extends string | number | bigint

    一个数字或者数字字符串或者bigint

  • n2 extends string | number | bigint

    同上

  • TargetType extends string | number | bigint = TypeOf<n1>

    输出的目标类型,默认与n1的类型相同,n1如果是字符串那么返回也是字符串,如果是数字返回也是数字,可以显式指定

Returns

返回经过计算的结果

Example

Plus<1, 1> // 2
Plus<"1", "1"> // "2"
Plus<1, 1, string> // "2"

Generated using TypeDoc