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
Copy file name to clipboardExpand all lines: readme.md
+16-22
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,18 @@
2
2
3
3
> Check TypeScript type definitions
4
4
5
-
6
5
## Install
7
6
8
-
```
9
-
$ npm install tsd
7
+
```sh
8
+
npm install tsd
10
9
```
11
10
12
-
13
11
## Overview
14
12
15
13
This tool lets you write tests for your type definitions (i.e. your `.d.ts` files) by creating files with the `.test-d.ts` extension.
16
14
17
15
These `.test-d.ts` files will not be executed, and not even compiled in the standard way. Instead, these files will be parsed for special constructs such as `expectError<Foo>(bar)` and then statically analyzed against your type definitions.
18
16
19
-
20
17
## Usage
21
18
22
19
Let's assume we wrote a `index.d.ts` type definition for our concat module.
@@ -132,8 +129,12 @@ By default, `tsd` applies the following configuration:
132
129
{
133
130
"strict":true,
134
131
"jsx":"react",
135
-
"target":"es2017",
136
-
"lib": ["es2017"],
132
+
"target":"es2020",
133
+
"lib": [
134
+
"es2020",
135
+
"dom",
136
+
"dom.iterable"
137
+
],
137
138
"module":"commonjs",
138
139
// The following option is set and is not overridable.
139
140
// It is set to `nodenext` if `module` is `nodenext`, `node16` if `module` is `node16` or `node` otherwise.
@@ -154,7 +155,7 @@ These options will be overridden if a `tsconfig.json` file is found in your proj
154
155
}
155
156
```
156
157
157
-
*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option.
158
+
*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option.
158
159
159
160
## Assertions
160
161
@@ -196,23 +197,20 @@ Print the type of `value` as a warning.
196
197
197
198
Useful if you don't know the exact type of the expression passed to `printType()` or the type is too complex to write out by hand.
198
199
199
-
200
200
## Programmatic API
201
201
202
202
You can use the programmatic API to retrieve the diagnostics and do something with them. This can be useful to run the tests with AVA, Jest or any other testing framework.
203
203
204
204
```ts
205
205
importtsdfrom'tsd';
206
206
207
-
(async () => {
208
-
const diagnostics =awaittsd();
207
+
const diagnostics =awaittsd();
209
208
210
-
console.log(diagnostics.length);
211
-
//=> 2
212
-
})();
209
+
console.log(diagnostics.length);
210
+
//=> 2
213
211
```
214
212
215
-
### tsd([options])
213
+
### tsd(options?)
216
214
217
215
Retrieve the type definition diagnostics of the project.
218
216
@@ -222,25 +220,21 @@ Type: `object`
222
220
223
221
##### cwd
224
222
225
-
Type: `string`<br>
223
+
Type: `string`\
226
224
Default: `process.cwd()`
227
225
228
226
Current working directory of the project to retrieve the diagnostics for.
229
227
230
228
##### typingsFile
231
229
232
-
Type: `string`<br>
230
+
Type: `string`\
233
231
Default: The `types` property in `package.json`.
234
232
235
233
Path to the type definition file you want to test. This can be useful when using a test runner to test specific type definitions per test.
236
234
237
235
##### testFiles
238
236
239
-
Type: `string[]`<br>
237
+
Type: `string[]`\
240
238
Default: Finds files with `.test-d.ts` or `.test-d.tsx` extension.
241
239
242
240
An array of test files with their path. Uses [globby](https://github.com/sindresorhus/globby) under the hood so that you can fine tune test file discovery.
0 commit comments