1

我目前已经开始使用 Typescript,并且已经使用了几天,一切正常(Emmet、linting 等),但是当我打开用 JavaScript 编写的旧项目时,vs 代码给了我警告以及有关打字的错误以及与打字稿相关的内容。不知何故,Vs Code 无法识别我正在使用 JavaScript。

PS。我正在开发一个 vue (nuxt) 项目,而 Vetur 插件正在处理语法高亮、linting 等...

错误示例:声明了“modifyHtml”,但它的值从不读取。ts(6133)

'CombinedVueInstance<Record<never, any> & Vue, object, object, object, Record<never, any>>'.Vetur(2339) 类型不存在属性 '$store'

这是我的 settings.js:

    {
  "workbench.iconTheme": "material-icon-theme",
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "liveServer.settings.donotShowInfoMsg": true,
  "editor.linkedEditing": true,
  "liveServer.settings.donotVerifyTags": true,
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "eslint.format.enable": true,
  "emmet.includeLanguages": {
    "javascript": "javascriptreact",
    "vue-html": "html",
    "vue-css": "css",
    "razor": "html",
    "plaintext": "jade"
  },
  "emmet.excludeLanguages": ["markdown"],
  "[dart]": {
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.selectionHighlight": false,
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "editor.suggestSelection": "first",
    "editor.tabCompletion": "onlySnippets",
    "editor.wordBasedSuggestions": false
  },
  "git.confirmSync": false,
  "javascript.updateImportsOnFileMove.enabled": "always",
  "nativescript.analytics.enabled": true,
  "editor.suggestSelection": "first",
  "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
  "java.configuration.checkProjectSettingsExclusions": false,
  "sonarlint.rules": {
    "java:S106": {
      "level": "off"
    },
    "javascript:S1117": {
      "level": "off"
    }
  },
  "workbench.preferredDarkColorTheme": "GitHub Dark",
  "workbench.preferredHighContrastColorTheme": "GitHub Dark",
  "workbench.preferredLightColorTheme": "Visual Studio Dark",
  "[json]": {
    "editor.quickSuggestions": {
      "strings": true
    },
    "editor.suggest.insertMode": "replace"
  },
  "files.autoSave": "afterDelay",
  "typescript.updateImportsOnFileMove.enabled": "always",
  "vetur.experimental.templateInterpolationService": true,
  "cSpell.userWords": ["vuex"],
  "workbench.colorTheme": "GitHub Dark",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-expand-multiline"
    },
    "prettyhtml": {
      "printWidth": 100,
      "singleQuote": false,
      "wrapAttributes": false,
      "sortAttributes": false
    }
  },
  "files.associations": {
    "*.vue": "vue"
  },
  "eslint.validate": ["javascript", "javascriptreact", "vue"],
  "vetur.grammar.customBlocks": {
    "docs": "md",
    "i18n": "json"
  },
  "window.zoomLevel": -1,
  "json.schemas": []
}

这是 VS Code 上的错误截图

4

3 回答 3

1

这对我有用。在我的工作区settings.json

{
  "vetur.validation.interpolation": false
}

这是我的jsonfig.json设置:

{
  "include": ["./src/**/*"]
}
于 2021-08-03T12:29:37.890 回答
1

如果您有 tslint,请尝试禁用它。这可能会解决问题,但有时这些错误也会出现在 eslint 中

于 2021-06-07T08:43:54.520 回答
0

我想我有同样的问题。我花了一段时间才弄清楚,但我想我知道了。要禁用 JavaScript 文件的类型检查,请添加checkJs: false到项目根目录中compilerOptions的您的部分。jsconfig.json

这是我的jsconfig.json

{
    "include": ["./src/**/*"],
    "compilerOptions": {
        "checkJs": false
    }
}

于 2021-09-30T09:25:40.173 回答