You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* refactor: reduce unnecessary logics
* refactor(parser): refactor splitStatemtents
* refactor: refactor serialization flow
* chore(vscode): use transpileOnly
* 2.0.0-alpha.0
* fix: load all files on create program
* 2.0.0-alpha.1
* refactor: tidy up
* refactor(v2): separate main API into type injection and printer
* refactor(v2): update interfaces
* chore: readme
* 2.0.0
This is the core API of `typeshot`. You can get TypeToken (token to print resolved type of `Target`).
17
17
18
-
Register types that you want to take snapshot.
18
+
When `Target` is a type reference and type arguments of the reference include the type `typeshot.T`, `typeshot.T` will be replaced with returned values type of given `parameters`. If there are multiple `typeshot.T`, they will be replaced from left to right. You can use `typeshot.T` in deeply nested type argument too.
This is dependency file that is loaded from `sample.typeshot.ts`.
20
+
`parameters` is array of function that recieves props and returns a value of parameter you inject to `Target`. The value will be internally converted into appropriate AST(Abstract Syntax Tree) node so that you don't have to use TypeScript Compiler API. See `typeshot.createParameter` section about how to set up `parameters`.
70
21
22
+
There are three kind of TypeToken (alias, interface and literal) and several approaches to get tokens.
71
23
```ts
72
-
exportinterfaceType {
73
-
foo:string;
74
-
bar: {
75
-
baz:number;
76
-
qux:Date;
77
-
};
78
-
}
79
-
80
-
exporttypeGenericType<Textendsstring> = {
81
-
[KinT]: { type:K };
82
-
};
83
-
```
24
+
const type =typeshot.createType<Target, Props>([...parameters]);
84
25
85
-
#### run-typeshot.ts
86
-
There is no CLI for `typeshot` yet.
87
-
```ts
88
-
importrunTypeshotfrom'typeshot/program';
89
-
90
-
runTypeshot({ test:/\.typeshot\.ts$/ });
91
-
```
26
+
typeshot.print`
27
+
// Target as type alias format, the name is 'TypeAsAlias'
28
+
export ${type(props).alias('TypeAsAlias')}
92
29
93
-
Execute via `ts-node`
30
+
// Target as interface format, the name is 'TypeAsInterface'
The tail of statement, tagged template string is written in output after symbols are replaced with generated type. It is described later section about symbols.
72
+
This helps to set up parameter function for the sake of `typeshot.createType`. The value of parameter have to be wrapped by `typeshot.solo`, `typeshot.union`, or `typeshot.intersection`. As their name, you can create Union Type and Intersection Type with `union` and `intersection`. `solo` is for single type.
This accumulates output contents immediately. You can use Type Token but a function.
188
77
189
-
The difference from `typeshot.takeStatic` is that the second argument doesn't exist, two extra phases `parameters` and `names` are added, `typeshot.T` is available in entry type, and function is available in tagged template.
78
+
### `typeshot.createPrinter<Props>`
79
+
This returns a printer function to accumulate output contents. You can use a function in template substitutions.
190
80
191
-
The `parameters` phase is for specifying replacement of `typeshot.T`.<br>
192
-
You can use `typeshot.T` multiple times. The order that aliases are replaced is left to right, even if the entry type is deeply nested.<br>
193
-
I recommend you to prepare type injection with `typeshot.createParameter`. It helps you to create injection with value typed correctly.
81
+
### `typeshot.createTemplate<Props>`
82
+
WIP
194
83
195
-
The `name` phase is for specifying name of generated type.<br>
196
-
You can use two kinds of name descriptors. One is to use string as same as the second argument of `takeStatic`.<br>
197
-
Another one is object(`Record<string, string>`) or array(`string[]`). When you use this way, the generated type is not entry type itself. `typeshot` use each type of property that is referred with keys of the object or array, and value of the key will be used as name.
84
+
### `// typeshot-start` and `// typeshot-end` Comments
198
85
199
-
As the example, you can use function in the tagged template.
86
+
Lines before `// typeshot-start` and lines after `// typeshot-end` are kept in output file. Both are optional so that you can skip it.
200
87
201
-
You can set the type of argument of each function in the type parameter of `parameters` phase.
88
+
Some types or values should still necessary in the output file. You can write such code by using these comments.
202
89
203
-
####`typeshot.configuration`
90
+
### `typeshot.config`
204
91
205
92
You can specify path of output file and header content of output file.
||`CONTENT`| content of output type, generally object literal |
218
-
||`DECLARATION`| completed content of output type, as type alias |
219
-
220
-
#### Types
221
-
| name | description |
222
-
|:--------------- |:----------- |
223
-
|`typeshot.T`| Type alias that will be replaced by dynamic parameter. See `typeshot.createDynamic` section about detail. |
224
-
|`typeshot.Expand`| Generic type that helps to serialize types declared as `interface`.<br> For example, if `Type` in the example above was not wrapped with `typeshot.Expand`, it is serialized to `Type`, not object literal. |
225
-
226
-
### Section Comments
227
-
228
-
`typeshot` splits input file into several sections by spesific comments. Supports only single line comment.
229
-
```ts
230
-
console.log('unknown, will be ignored');
231
-
232
-
// section-comment-A
233
-
console.log('section A start');
234
-
/* statements */
235
-
console.log('section A end');
236
-
237
-
// section-comment-B
238
-
console.log('section B start');
239
-
/* statements */
240
-
console.log('section B end');
241
-
```
242
-
243
-
Statements in each section are treated in different way.
244
-
245
-
| section name | kept or not in output | what kind of code should be written |
0 commit comments