Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VSCode、typescript、eslint和prettier->;空检查不起作用_Typescript_Eslint_Prettier - Fatal编程技术网

VSCode、typescript、eslint和prettier->;空检查不起作用

VSCode、typescript、eslint和prettier->;空检查不起作用,typescript,eslint,prettier,Typescript,Eslint,Prettier,我试着将TypeScriptLinting设置为使用prettier,而prettier工作时,我似乎丢失了基本的typescript错误检查。我怎样才能找回这个 ^应该抱怨访问foo上的.value Mytsconfig.json { "compilerOptions": { "outDir": "./dist/", "noImplicitAny": true, "module": "es6", "target": "es5", "jsx": "r

我试着将TypeScriptLinting设置为使用prettier,而prettier工作时,我似乎丢失了基本的typescript错误检查。我怎样才能找回这个

^应该抱怨访问
foo
上的
.value

My
tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "sourceMap": true,
    "moduleResolution": "node",
    "baseUrl": "./src",
    "allowSyntheticDefaultImports": true,
    "paths": {
      "~/*": ["./*"]
    }
  },
}
{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "plugins": ["@typescript-eslint", "prettier"],
  "env": {
    "browser": true,
    "jasmine": true,
    "jest": true,
    "es6": true
  },
  "rules": {
    "prettier/prettier": [
      "error", 
      { "singleQuote": true, "semi": false }
    ],
    "@typescript-eslint/no-use-before-define": "off",
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/class-name-casing":  ["error", { "allowUnderscorePrefix": true }],
    "@typescript-eslint/interface-name-prefix": ["error", { "prefixWithI": "always", "allowUnderscorePrefix": true}],
    "@typescript-eslint/no-unused-vars": ["error", { "args": "none"}],
    "@typescript-eslint/no-non-null-assertion": "off",
    "semi":"off"
  },
  "parser": "@typescript-eslint/parser"
}
.eslintrc.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "sourceMap": true,
    "moduleResolution": "node",
    "baseUrl": "./src",
    "allowSyntheticDefaultImports": true,
    "paths": {
      "~/*": ["./*"]
    }
  },
}
{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "plugins": ["@typescript-eslint", "prettier"],
  "env": {
    "browser": true,
    "jasmine": true,
    "jest": true,
    "es6": true
  },
  "rules": {
    "prettier/prettier": [
      "error", 
      { "singleQuote": true, "semi": false }
    ],
    "@typescript-eslint/no-use-before-define": "off",
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/class-name-casing":  ["error", { "allowUnderscorePrefix": true }],
    "@typescript-eslint/interface-name-prefix": ["error", { "prefixWithI": "always", "allowUnderscorePrefix": true}],
    "@typescript-eslint/no-unused-vars": ["error", { "args": "none"}],
    "@typescript-eslint/no-non-null-assertion": "off",
    "semi":"off"
  },
  "parser": "@typescript-eslint/parser"
}

为什么
foo.value
应该是错误的
foo
是一个包含值作为变量的对象,
logFoo(foo:{value:number | null})
@PareshLomate
foo
的类型是
{value:number}null
,因此
foo
可以是
null
,如果
foo===null
我就不能访问
foo.value
你是说
tsc
strictNullChecks
(或者更全面的
strict
,包括
strictNullChecks
)吗?您的配置中没有这些选项,如果我启用上述选项,编译器将再次发出错误。请写一个答案,我将接受它。谢谢