Home

Awesome

TypeType Examples

This repository contains examples of using typetype to create typescript types, typetype is designed to generate complex typescript type with ease.

For example, to implement StringToUnion in 531-medium-string-to-union:

export type function StringToUnion = (T extends string) => ^{
    if(T extends `${infer char}${infer rest}`) {
        return union [char, StringToUnion<rest>]
    } else {
        return never
    }
}

The output will be:

export type StringToUnion<T extends string> = T extends `${infer char}${infer rest}` ? (char | StringToUnion<rest>) : never;

See it in action!

Outline

foreach example-set in this repo:
    input = examples/<example-set>/<example-name>.type
    output = examples/<example-set>/<example-name>.ts
    test = examples/<example-set>/<example-name>.test.ts

Local setup

> npm install
> npm run dev

License

This project is MIT licensed.