Skip to content

Commit 0ae958d

Browse files
committed
Add description
1 parent cc818f6 commit 0ae958d

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
# compile-time-typescript
22

3-
## Usage
3+
## Install
44

5+
```shell
6+
$ git clone https://github.com/n4o847/compile-time-typescript
7+
$ cd compile-time-typescript
8+
$ npm install
59
```
10+
11+
## Usage
12+
13+
```shell
614
$ echo -n "world" | npx ts-node src examples/hello.ts
715
Hello, world!
816
```
17+
18+
## Test
19+
20+
```shell
21+
$ npm test
22+
```
23+
24+
## How it works
25+
26+
We can write a program like this:
27+
28+
```typescript
29+
type Main<Input extends string> = `Hello, ${Input}\n`;
30+
export default Main;
31+
```
32+
33+
Compile-time-typescript saves the program as `callee.ts` and creates `caller.ts`:
34+
35+
```typescript
36+
import Main from './callee';
37+
type Input = "HERE COMES THE INPUT";
38+
type Output = Main<Input>;
39+
```
40+
41+
So the program must have a default export of a generic type that takes a type parameter and constructs a string literal type.
42+
43+
Then compile-time-typescript type-checks `caller.ts` and extracts the type information of `Output`.
44+
45+
If `Output` is a string literal type, its content is printed. Otherwise, an error occurrs.

0 commit comments

Comments
 (0)