Skip to content

Commit

Permalink
Require Node.js 14
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 30, 2022
1 parent c6c2ec4 commit 8ab9869
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"email": "[email protected]",
"url": "https://github.com/SamVerschueren"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"bin": "dist/cli.js",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": "./dist/cli.js",
"engines": {
"node": ">=12"
"node": ">=14.16"
},
"scripts": {
"prepublishOnly": "npm run build",
Expand All @@ -39,7 +39,7 @@
"typedefinitions"
],
"dependencies": {
"@tsd/typescript": "~4.7.3",
"@tsd/typescript": "~4.7.4",
"eslint-formatter-pretty": "^4.1.0",
"globby": "^11.0.1",
"meow": "^9.0.0",
Expand All @@ -48,7 +48,7 @@
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@types/node": "^14.0.0",
"@types/node": "^14.18.21",
"@types/react": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
Expand All @@ -61,7 +61,7 @@
"execa": "^5.0.0",
"react": "^16.9.0",
"rxjs": "^6.5.3",
"typescript": "^4.3.2"
"typescript": "~4.7.4"
},
"ava": {
"timeout": "2m",
Expand Down
38 changes: 16 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

> Check TypeScript type definitions

## Install

```
$ npm install tsd
```sh
npm install tsd
```


## Overview

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.

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.


## Usage

Let's assume we wrote a `index.d.ts` type definition for our concat module.
Expand Down Expand Up @@ -132,8 +129,12 @@ By default, `tsd` applies the following configuration:
{
"strict": true,
"jsx": "react",
"target": "es2017",
"lib": ["es2017"],
"target": "es2020",
"lib": [
"es2020",
"dom",
"dom.iterable"
],
"module": "commonjs",
// The following option is set and is not overridable.
// It is set to `nodenext` if `module` is `nodenext`, `node16` if `module` is `node16` or `node` otherwise.
Expand All @@ -154,7 +155,7 @@ These options will be overridden if a `tsconfig.json` file is found in your proj
}
```

*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option.
*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option.

## Assertions

Expand Down Expand Up @@ -196,23 +197,20 @@ Print the type of `value` as a warning.

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.


## Programmatic API

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.

```ts
import tsd from 'tsd';

(async () => {
const diagnostics = await tsd();
const diagnostics = await tsd();

console.log(diagnostics.length);
//=> 2
})();
console.log(diagnostics.length);
//=> 2
```

### tsd([options])
### tsd(options?)

Retrieve the type definition diagnostics of the project.

Expand All @@ -222,25 +220,21 @@ Type: `object`

##### cwd

Type: `string`<br>
Type: `string`\
Default: `process.cwd()`

Current working directory of the project to retrieve the diagnostics for.

##### typingsFile

Type: `string`<br>
Type: `string`\
Default: The `types` property in `package.json`.

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.

##### testFiles

Type: `string[]`<br>
Type: `string[]`\
Default: Finds files with `.test-d.ts` or `.test-d.tsx` extension.

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.

## License

MIT © [Sam Verschueren](https://github.com/SamVerschueren)
4 changes: 2 additions & 2 deletions source/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export default (pkg: PackageJsonWithTsdConfig, cwd: string): Config => {
compilerOptions: {
strict: true,
jsx: JsxEmit.React,
lib: parseRawLibs(['es2017', 'dom', 'dom.iterable'], cwd),
lib: parseRawLibs(['es2020', 'dom', 'dom.iterable'], cwd),
module,
target: ScriptTarget.ES2017,
target: ScriptTarget.ES2020,
esModuleInterop: true,
...combinedCompilerOptions,
moduleResolution: module === ModuleKind.NodeNext ?
Expand Down

0 comments on commit 8ab9869

Please sign in to comment.