Skip to content

majjoha/typology

Repository files navigation

Typology

CI

Typology is a playground for exploring type-level programming in TypeScript. The various types range from simple representations of natural numbers to types that can compute Fibonacci numbers.

Examples

Addition

const three: Add<Succ<Zero>, Succ<Succ<Zero>>> = {
  n: {
    n: {
      n: "zero"
    },
  },
}

Factorial

const six: Factorial<Three> = { n: { n: { n: { n: { n: { n: "zero" } } } } } }

Convert strings to numbers

const five: FromString<"{ n: { n: { n: { n: { n: zero } } } } }"> = {
  n: { n: { n: { n: { n: "zero" } } } },
}

Boolean logic

const two: IfElse<
  And<
    LessThan<Four, Six>,
    Not<GreaterThan<Five, Ten>>
  >,
  ToString<Succ<Succ<Zero>>>,
  never
> = "{ n: { n: zero } }"

Fibonacci numbers

const five: Fibonacci<Five> = { n: { n: { n: { n: { n: "zero" } } } } }

License

See LICENSE.