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
`typeshot.registerTypeDefinition` is a core API to create custom type definitions. It receives a function to describe type definition and returns a function to instantiate type definition.
103
+
`typeshot.registerTypeDefinition` is a core API to create custom type definitions. It receives a function to describe type definition and returns a function to instantiate type definition.`typeshot` converts returned value of the describer function into type definitions by parsing the value down to `TypeFragment` and usual values and evaluating them. You can see how `typeshot` evaluates `TypeFragment` and values, by enabling a CLI Option `-E`/`--emitIntermediateFiles`.
104
104
105
-
The describer function receives a utility function called `createTypeFragment` and arguments which come from the instantiator function.
105
+
The describer function receives a utility function called `createTypeFragment` and rest arguments which come from the instantiator function. There are two steps to instantiate type definitions, the first step is to pass arguments that the describer function requires, and the second step is to specify type format and type name.
106
106
107
-
`typeshot` converts returned value of the describer function into type definitions by parsing the value down to `TypeFragment` and usual values and evaluating them.
108
-
109
-
You can see how `typeshot` evaluates `TypeFragment` and values, by enabling a CLI Option `-E`/`--emitIntermediateFiles`.
107
+
In this example, it passes `paths` to describer function and specifies to output the instance as interface named `FileInformationMap`. Make sure to use `typeshot.print` to commit instances to the result.
`TypeFragment` is a special object which contains information to connect values and types.
@@ -122,7 +126,7 @@ const fragment = createTypeFragment<{ [K in typeof p]: FileType[typeof extname]
122
126
123
127
Note that the names of type query target must match with the keys of object at the argument.
124
128
125
-
### Intersection Types
129
+
####Intersection Types
126
130
As the example does, you can merge `TypeFragment` into a one object. Merged object is evaluated as an intersection type. In this example, it's internally evaluated as like this:
127
131
```ts
128
132
& { [Kin'./foo/bar.ts']: FileType['.ts'] }
@@ -164,9 +168,9 @@ type Example = ${example().literal()};
164
168
This example will be evaluated into `type Example = 'foo' | 'bar' | 'baz';`.
165
169
166
170
### `print`
167
-
To commit type definition instance to result, you need to use `typeshot.print`. It's accepts Tagged Template Literal.
171
+
`typeshot.print` is a tag function to commit type definition instance to result.
168
172
169
-
As the example does, you can specify type format and name. You can specify extra strings to add comments, modifiers, etc.
173
+
As the example does, it accepts extra contents to add comments, modifiers, etc.
0 commit comments