https://github.com/mistlog/typetype-examples
Examples of using typetype to create typescript types
https://github.com/mistlog/typetype-examples
type typescript typetype
Last synced: 8 months ago
JSON representation
Examples of using typetype to create typescript types
- Host: GitHub
- URL: https://github.com/mistlog/typetype-examples
- Owner: mistlog
- License: mit
- Created: 2021-02-14T07:09:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-04T03:10:32.000Z (almost 5 years ago)
- Last Synced: 2025-06-11T11:44:05.317Z (9 months ago)
- Topics: type, typescript, typetype
- Language: TypeScript
- Homepage:
- Size: 258 KB
- Stars: 33
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TypeType Examples
This repository contains examples of using [typetype](https://github.com/mistlog/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](https://github.com/type-challenges/type-challenges/blob/master/questions/531-medium-string-to-union/README.md):
```ts
export type function StringToUnion = (T extends string) => ^{
if(T extends `${infer char}${infer rest}`) {
return union [char, StringToUnion]
} else {
return never
}
}
```
The output will be:
```ts
export type StringToUnion = T extends `${infer char}${infer rest}` ? (char | StringToUnion) : never;
```
See it in action!
* https://mistlog.github.io/typetype-playground/
## Outline
```ts
foreach example-set in this repo:
input = examples//.type
output = examples//.ts
test = examples//.test.ts
```
* syntax: the grammar of typetype
* url-parser
* url-parser: simple url parser, parse individual part of url
* url-parser-2: parse url as a whole
* type-challenges
* solutions of [type-challenges](https://github.com/type-challenges/type-challenges) in typetype
## Local setup
```bash
> npm install
> npm run dev
```
## License
This project is [MIT licensed](https://github.com/mistlog/typetype-examples/blob/main/LICENSE).