-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
new-challengePropose a new challenge, a PR will be auto generatedPropose a new challenge, a PR will be auto generatedts4.1
Description
Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes.
Detailed solution/guide is not required, but please be sure the challenge is solvable.
Info
difficulty: hard # medium / hard / extreme
title: Implement addition in the type system
#tags: tuple # separate by commaQuestion
In addition to string literal types, TypeScript supports numeric literal types:
type One = 1
type TwoOrThree = 2 | 3If you have two numbers, it's natural to want to add them! For example:
type T1 = Add<1, 2> // should be 3
type T2 = Add<2, 3 | 4> // should be 5 | 6
type T3 = Add<1 | 2, 3 | 4> // should be 4 | 5 | 6Template
type Add<A extends number, B extends number> = anyTest Cases
import { Equal, Expect, ExpectFalse, NotEqual } from '@type-challenges/utils'
type cases = [
Expect<Equal<Add<1, 2>, 3>>,
Expect<Equal<Add<2, 3 | 4>, 5 | 6>>,
Expect<Equal<Add<1 | 2, 3 | 4>, 4 | 5 | 6>>,
]Metadata
Metadata
Assignees
Labels
new-challengePropose a new challenge, a PR will be auto generatedPropose a new challenge, a PR will be auto generatedts4.1