如何修复 Typescript linting 在 VSCode 中不起作用的问题?

Hen*_*nry 4 typescript eslint tslint visual-studio-code

在我的 settings.json 中,我有:

"eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ]
Run Code Online (Sandbox Code Playgroud)

然而我的打字稿支持不起作用。它在运行时捕获错误,但不显示红色波浪线(下面的示例)。

启用 ESLint 时我也会收到错误,并且当我启用 ESLint 时 Prettier 不起作用:

ESLint: Failed to load parser '@typescript-eslint/parser' declared in 'template/.eslintrc.js': Cannot find module 'typescript' Require stack: - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cli-engine.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/index.j
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

在此输入图像描述

Hen*_*nry 6

解决此问题的方法是按照以下步骤操作:

  1. 关闭 VSCode

  2. CD 进入应用程序

/Users/<user>/Library/Application\ Support
Run Code Online (Sandbox Code Playgroud)
  1. 检查 VSCode 文件夹所在位置(查找是 code/ 还是 .vscode/)
ls
Run Code Online (Sandbox Code Playgroud)
  1. 删除 VSCode 文件夹
rm -rf code/ or .vscode/
Run Code Online (Sandbox Code Playgroud)
  1. 打开 VSCode - 那里应该有你所有的扩展,但是像你的主题、扩展设置之类的东西不会被配置 -

  2. 现在所有内容(扩展设置、主题等)都将被重置