למה מקבלים ב-TypeScript את השגיאה של Eslint "תנאי מיותר, הערך תמיד אמת eslint@typescript-eslint/no-unnecessary-condition"
יש לי את הדוגמאות האלה (בין היתר, מעבר ל-TypeScript מ-JS).
איפה let diff=(oldIndent - newIndent)/2 על האחרון.
למה זה קורה? האם זו איזו תקלה? מה אני עושה לא נכון?
.prettierrc
{
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 64,
"tabWidth": 2,
"useTabs": false,
"arrowParens": "avoid",
"quoteProps": "as-needed",
"bracketSpacing": true,
"proseWrap": "always",
"endOfLine": "lf",
"singleAttributePerLine": true,
"prettierPath": "./node_modules/prettier"
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["es2020"],
"outDir": "host",
"rootDir": "make",
"sourceMap": true,
"strictNullChecks": true
},
"include": ["make"],
"exclude": ["node_modules"]
}
.eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": ["./tsconfig.json"]
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [],
"rules": {
"curly": 2,
"brace-style": ["error", "1tbs"],
"@typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"@typescript-eslint/no-unnecessary-condition": {
"allowConstantLoopConditions": true
}
}
}
.vscode/settings.json
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
"eslint.nodePath": "./node_modules/eslint",
"eslint.packageManager": "npm"
}
זה נהיה מוזר.... ניסיתי לסגור ולפתוח את הקובץ שוב, אבל אותן בעיות. (הקווים המתפתלים כאן מראים את אותה הבעיה).
שימו לב איך זה מופיע הרבה במקומות אקראיים (כפי שמוצג בצד הסרגל הימני).




