1.4.1 • Published 2 years ago

compile-time-typescript v1.4.1

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

compile-time-typescript

Enjoy type-level programming with TypeScript!

Installation

$ npm install -g compile-time-typescript

Usage

$ ctts script.ts

Examples

There are several examples under examples/. For example, hello.ts:

type Main<Input extends string> = `Hello, ${Input}!\n`;
export default Main;
$ echo -n "world" | ctts hello.ts
Hello, world!

Remarkable features of TypeScript

How it works

When ctts script.ts is executed, compile-time-typescript creates a caller like this:

import Main from "/path/to/script";
type Input = "HERE COMES THE INPUT";
type Output = Main<Input>;

So the program must have a default export of a generic type that takes a type parameter and constructs a string literal type.

Then compile-time-typescript type-checks the caller and extracts the type information of Output.

If Output is a string literal type, its content is printed. Otherwise, an error occurs.

Where it is used

  • hakatashi/esolang-box - Easy and standardized docker images for 200+ esoteric (and non-esoteric) languages.

Resources

1.4.1

2 years ago

1.4.0

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago