# Sum

`type` in `services` · v0.8.2

<https://docs.seedcord.org/packages/services/0.8.2/types/sum>

Returns the sum of two numbers.

Note: - A or B can only support `-999` ~ `999`.

## Examples

```ts
import type {Sum, PositiveInfinity, NegativeInfinity} from 'type-fest';

type A = Sum<111, 222>;
//=> 333

type B = Sum<-111, 222>;
//=> 111

type C = Sum<111, -222>;
//=> -111

type D = Sum<PositiveInfinity, -9999>;
//=> Infinity

type E = Sum<PositiveInfinity, NegativeInfinity>;
//=> number

 Numeric
```

## Declaration

```ts
type Sum<A extends number, B extends number> = number extends A | B ? number // Handle cases when A and B are both +/- infinity : A extends B & (PositiveInfinity | NegativeInfinity) ? A // A or B could be used here as they are equal // Handle cases when A and B are opposite infinities : A | B extends PositiveInfinity | NegativeInfinity ? number // Handle cases when A is +/- infinity : A extends PositiveInfinity | NegativeInfinity ? A // Handle cases when B is +/- infinity : B extends PositiveInfinity | NegativeInfinity ? B // Handle cases when A or B is 0 or it's the same number with different signs : A extends 0 ? B : B extends 0 ? A : A extends ReverseSign<B> ? 0 // Handle remaining regular cases : SumPostChecks<A, B>
```
