File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change 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
715Hello, 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.
You can’t perform that action at this time.
0 commit comments