Skip to content

Commit

Permalink
Add type check for declaration files in yarn test
Browse files Browse the repository at this point in the history
It looks like in tsconfig.json, the `skipLibCheck` flag was added
so that check-dts could ignore these external errors:

```
✖ node_modules/@types/node/globals.d.ts:67:13: Type error TS2502
  'AbortController' is referenced directly or indirectly in its own type annotation.

✖ node_modules/@types/node/globals.d.ts:74:13: Type error TS2502
  'AbortSignal' is referenced directly or indirectly in its own type annotation.
```

See the check-dts FAQ for their guidance:
https://github.com/ai/check-dts/blob/7020f61159798fbe19d2a1e38aadd75ab0c7ccc5/README.md#i-am-getting-an-error-from-node-types-how-do-i-skip-node_modules

But adding that flag meant the type declaration files (*.d.ts) in
this anycable-client repo were skipped, so any errors were
overlooked. This has downstream effects for any consumers of the
anycable-core or anycable-web packages. If any declaration files
had type errors (as they did), and the consumers did not set
`skipLibCheck` in their tsconfig, then they'd experience
a failure in their repo as evidenced in issue #39.

So it's prudent for us to _not_ skip checking the type declarations.

`tsc` and `check-dts` both read from tsconfig.json, but we can point
`tsc` to a different configuration file that omits `skipLibCheck`
and ensures this repo's declaration files are checked.

Added the tsc type check at the front because it's the quickest test,
so tests will fail early and fast if there's an error.
  • Loading branch information
cmdoptesc committed Apr 30, 2024
1 parent 3e3b547 commit c57c9ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions noskiplibcheck_tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowJs": true,
"strict": true,
"noEmit": true,
"lib": [
"ES2020.Promise",
"DOM"
],
"types": [
"node",
"jest"
]
},
"include": ["packages/**/*.d.ts"],
"exclude": [
"**/errors.ts"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"type": "module",
"scripts": {
"test:dev": "NODE_OPTIONS='--experimental-vm-modules' jest",
"test": "yarn test:dev --coverage && check-dts",
"test": "tsc -p noskiplibcheck_tsconfig.json && yarn test:dev --coverage && check-dts",
"lint": "eslint . && prettier --check 'packages/**/*.{js,ts}'",
"lint:fix": "eslint . --fix && prettier --check 'packages/**/*.{js,ts}' --write",
"protos": "yarn protos:build && yarn protos:fix",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"allowJs": true,
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"skipLibCheck": true, // otherwise check-dts fails AbortController + AbortSignal
"lib": [
"ES2020.Promise",
"DOM"
Expand Down

0 comments on commit c57c9ea

Please sign in to comment.