-
Notifications
You must be signed in to change notification settings - Fork 6
chore: Fix typechecks #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f0a30eb to
71c6bfa
Compare
| 'scripts.test', | ||
| 'vitest run --config vitest.config.ts', | ||
| 'scripts.test:ts', | ||
| 'tsc --project tsconfig.test.json --noEmit', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was duplicated so I added the new one here
rekmarks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems completely insane that we can't do this as a lint step without building—I have spent too many hours trying, and it seems impossible—but this does work.
It appears that a better world is possible: we can both use `Node16` module resolution for builds _and_ test, lint, and develop directly from our source files. @sirtimid previously fixed #174 and #181 over several PRs: #192 #193 #194 #195 In #194, we concluded that there was no way to run type checks without building our source files. As it turns out, this is in fact possible by disabling [the `composite` config option](https://www.typescriptlang.org/tsconfig/#composite)[^1]. Having done this, we now run `lint:ts` as part of our regular lint scripts, which reliably works without building. In addition, this also fixes type errors in our `vitest.config.ts` files. So that we have this documented, let's review our config to understand why our new config works. In our root `tsconfig.json` and `tsconfig.package.json` (which package-level `tsconfig.json` files extend), we set the following: ```json { "module": "Preserve", "moduleResolution": "Node10", } ``` Using [`Node10` for `moduleResolution`](https://www.typescriptlang.org/tsconfig/#moduleResolution) causes TypeScript to ignore the `exports` field of `package.json`, which enables our [`paths` config](https://www.typescriptlang.org/tsconfig/#paths) in `tsconfig.packages.json` to correctly resolve our source files. Using [`Preserve` for `module`](https://www.typescriptlang.org/tsconfig/#preserve) simply appears to be compatible with our config. Other options, like `ES2015`, worked as well, but from the description of the setting it _sounds like_ what we want. Meanwhile, our `tsconfig.test.json` files have been renamed to `tsconfig.lint.json`, and they now look like this: ```json { "extends": "./tsconfig.json", "compilerOptions": { "composite": false, "noEmit": true, "skipLibCheck": true }, "include": ["./src"], "exclude": [] } ``` Due to [the semantics of `extends`](https://www.typescriptlang.org/tsconfig/#extends), `references` is omitted, and `include` and `exclude` _overwrite_ their inherited values. `skipLibCheck` ensures that we ignore errors in dependencies, and `noEmit` of course ensures that we don't actually produce any output files. We still use `Node16` as our `module` and `moduleResolution` options for actual builds, as is [recommended by `ts-bridge`](https://ts-bridge.dev/reference/configuration/#node16-module-resolution). There may come a time when this discrepancy causes trouble for us, but for now, it appears that we are in a happy place. [^1]: Boundless gratitude to microsoft/TypeScript#27069 (comment) for this insight
closes #181
createConfigfromeslint-metamaskfor the flat eslint config.test:tscommand that doestsc --noEmitwith a specified tsconfig to test for type issues on the source code and tests