[RFC] Enable type checking for tests
See original GitHub issueProposal
Delete this line in tsconfig.json:
Reasoning
-
This will allow the typescript compiler to check for type errrors in test files, which is extra armour on top of the tests themselves.
-
I can imagine API changes that don’t cause a test to fail but might still cause the test’s code to be an out-of-date usage example for that particular API.
-
The vscode TS plugin currently doesn’t work properly in test files because it has the default contextless TS config applied, rather than our own tsconfig.json file. This means that, e.g. absolute import paths show up as errors, but work fine when run under jest:
And of course if you choose to write test code that would fail type checking, you get other red squiggly lines that just add noise.
Exceptions
Sometimes we don’t care about types, or they get in the way. I would therefore recommend use of any
or @ts-ignore
or even .js
files if our setup supports that?
How
Turning type-checking on for test files and running tsc
introduces 243 errors. It would be a big old PR to fix them all in one go. So I’d recommend doing it in a staggered way:
- Turn on type-checking for tests
- Fix a handful of erroring test files
- If there are still erroring test files left over then turn off type-checking for tests
- Submit PR
- If there are still erroring test files left over then go to 1.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:13 (13 by maintainers)
Top GitHub Comments
I’m going to resolve this RFC now
Resolution
We decided to do it.
Level of Support
2: Positive feedback.
Next Steps
We will implement it. I’ll start doing chunks in my 20% time. Anyone who wants to help out, please do! 🙏
This work was completed in https://github.com/artsy/reaction/pull/1458