Hi, I have created a cli tool that automatically adds
@ts-expect-error to code with TypeScript type errors.
In this article, I will explain how to use this tool.
How to use
Just run the command in a project with
If you are using loose type checking, edit tsconfig.json to tighten type checking(e.g
$ npx suppress-ts-errors
This alone will add a
@ts-expect-errors comment to the location in that TypeScript project where there are type errors, and suppress the occurrence of type errors.
Of course, the
tsx code will be added in a comment format in line with
In addition, the
vue subcommand can be used to target type errors in the portion of Vue's SFC.
$ npx suppress-ts-errors vue "./src/**/*.vue"
This option also allows for flexible settings.
||Path to tsconfig.json.|
||Choice of inserted comment type.
||Add error code to comment. e.g. TS2345.|
Why I needed it
I am currently working on a project where type checking has not been tightened (cannot set
strict: true), and I would like to improve the situation.
In the meantime, new functions were being developed rapidly, and it was easy to create new code containing type errors. In order to solve this problem, we wanted to first tighten type checking so that newly added code would be type-protected, and then safely begin modification of existing code in that state.
To do this, we needed to add a comment (
@ts-ignore) to all existing type errors to nullify them, and we developed this CLI tool to automate this process.
All code is available on GitHub.
Thanks for reading.
Please send me a message if you need.
Top comments (0)