VSCode无法识别打字稿3.7.2功能

时间:2019-11-13 10:56:18

标签: typescript visual-studio-code

我正在使用VS Code 1.40.0,并且具有以下package.json

{
  "name": "test",
  "version": "0.0.1",
  "description": "test",
  "main": "./src/main.ts",
  "sideEffects": false,  
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.6.1",
    "@typescript-eslint/parser": "^2.6.1",
    "eslint": "^6.5.1",
    "typescript": "^3.7.2"
  },
  "dependencies": {
  }
}

以及以下tsconfig.json

{
    "compilerOptions": {
        "lib": [
            "es2019",
            "dom",
            "es2019.array"
        ],
        "target": "es6",
        "module": "es6",
        "strict": true,
        "strictBindCallApply": true,
        "strictFunctionTypes": true,
        "strictPropertyInitialization": true,
        "moduleResolution": "node",
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "strictNullChecks": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "alwaysStrict": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true
    }
}

但是在编写以下代码const a = null ?? 0;时,vscode抱怨,但是在按预期方式编译时,是否需要更改某些设置才能使vscode正确解析Typescript 3.7?

2 个答案:

答案 0 :(得分:0)

您可以将以下内容添加到设置中,以便它在您的node_modules中使用TypeScript而不是其内置的(可能仍在3.6上):

"typescript.tsdk": "node_modules/typescript/lib"

答案 1 :(得分:0)

安装JavaScript and TypeScript Nightly解决了我的问题。