74

While working on a TypeScript project, I commented out a line, and got the error:

Failed to compile

./src/App.tsx
(4,8): error TS6133: 'axios' is declared but never used.

This error occurred during the build time and cannot be dismissed.

The error is right, I am importing axios, but I wanted to temporarily comment out the call to axios.get. I appreciate that error as it keeps my imports clean, but during early development is is pretty disruptive.

Any way to disable or ignore that warning?

3 Answers 3

108

You probably have the noUnusedLocals compiler option turned on in your tsconfig.json. Just turn it off during development.

8
  • 3
    In my case I also forgot to restart npm run start for changes to take effect. Commented Jan 26, 2018 at 19:25
  • It won't if you disable noUnusedLocals in the tsconfig.json file you are using for buildiing.
    – Saravana
    Commented Mar 6, 2018 at 1:43
  • 33
    can this be set as a warning? Commented Mar 8, 2019 at 19:31
  • 2
    If anyone else is still getting the errors after changing the option make sure there aren't any other tsconfig files in your project. If you're using vscode open the command palette (ctrl + p) and start typing tsconfig to find other files. I had a tsconfig.app.json that was overriding the one at the root
    – Crhistian
    Commented Aug 16, 2019 at 13:07
  • 10
    This doesn't seem to work. By default noUsedLocals is false according to docs. However, omitting it still shows the error, and the error persists even with it being set to false. After TS server & vscode restart. There are no other tsconfig files either. Commented Dec 16, 2021 at 22:18
19

In tsconfig.json

{
  "compilerOptions": {
    ...
    "noUnusedLocals": false,   // just set this attribute false
  }
}

It will be done.

For more tips:

In xxx.ts file

//@ts-nocheck 
when on the top of the file,it will not check the below.

//@ts-ignore
when use it,it will not check the next line
12

I had the same problem in my React App. Apart from changing the "noUsedLocals": false property in the tsconfig.json, you also need to adjust the "noUnusedParameters": false. The former is only applicable to local variables, if you are passing unused parameters through functions, the latter will need to be changed to false as well.

In summary, you'll have to do the following:

{
  "compilerOptions": {
     "noUnusedLocals": false,
     "noUnusedParameters": false,
 }
}
1
  • 1
    I just set both of these values to false like in your example and restarted the TS server, and made sure I have only one tsconfig.json file. Doesn't work. Although in my case it's neither a local or parameter, it's a function. Commented Mar 14 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.