For example, the function JSON.parse(data) returns a type of any. So if you write something like this:
const parsed = JSON.parse('example');
console.log(parsed.somethingThatDoesntExist);
No error occurs in VSCode, despite having noImplicitAny set to true in my tsconfig.json, and my .eslintrc.js having the rule '@typescript-eslint/no-explicit-any': 'error'.
I have also tried adding the following rules to my eslintrc.js, however they seem to break all TypeScript error checking:
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
In an ideal world I would want this any to be presumed to be unknown, but an error would also be great.
Here is my eslintrc.js:
module.exports = exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
ecmaVersion: 2021,
},
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'prettier/prettier': [
'error',
{
trailingComma: 'all',
tabWidth: 2,
semi: true,
singleQuote: true,
bracketSpacing: true,
printWidth: 120,
endOfLine: 'auto',
},
],
},
};
and tsconfig.json:
{
"compilerOptions": {
"strict": true,
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"ES2021.String"
],
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "../build/",
"rootDir": ".",
"resolveJsonModule": true,
"composite": true,
"types": [],
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true
}
}