I believe I have found a solution.
1.) tsconfig
In tsconfig.json
, add the following. This will stop the compiler errors from appearing when building the project with npm run build
.
You will still get the yellow underline warnings for affected code lines in VSCode (if you haven't yet done anything else to address them).
"compilerOptions": {
/* Linting */
"noUnusedLocals": false,
"noUnusedParameters": false,
},
2.) eslintrc
In .eslintrc.cjs
, add the following. This will ensure that unused variables get marked as warnings. Alternative options would be to mark them as errors or to ignore them completely. Note that I am disabling the JS version, but enabling the TS version.
Again, you will still get the yellow underline warnings for affected code lines in VSCode (if you haven't yet done anything else to address them).
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
}
3.) eslint-disable
In the file where you want to disable a warning, add an inline rule. Note that, if you want to be specific, you have to add the TS version of the rule, e.g.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [instance, setInstance] = useState<SwiperClass | null>(null);
Alternatively, you can simply use // eslint-disable-next-line
without specifying the rule.