Mengapa mendapatkan TypeScript Eslint "Kondisi tidak perlu, nilainya selalu benar eslint@typescript-eslint/no-unnecessary-condition"


Saya memiliki contoh-contoh ini (di antara yang lain, beralih ke TypeScript dari JS).




Dimana let diff=(oldIndent - newIndent)/2 pada yang terakhir.

Kenapa ini terjadi? Apakah ini semacam bug? Apa yang saya lakukan salah?

.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"
}

Ini mulai aneh.... Saya mencoba menutup dan membuka file lagi, tapi masalahnya sama. (Garis bergelombang di sini menunjukkan masalah yang sama).

Perhatikan bagaimana itu muncul di banyak tempat secara acak (seperti yang ditunjukkan oleh bilah sisi di sebelah kanan).