【问题标题】:How to ignore "Could not find a declaration" error in VS Code and TypeScript如何忽略 VS Code 和 TypeScript 中的“找不到声明”错误
【发布时间】:2019-06-05 18:08:04
【问题描述】:

我正在使用 VS Code 处理 Typescript 和 Vue Cli。我在这一行收到“定义缺失警告”:

 import { setupCalendar, DatePicker } from "v-calendar";

找不到模块“v-calendar”的声明文件。

这个错误确实会影响 tsc 编译,但是 VS Code 总是在代码和导航栏显示这个错误

我可以做些什么来消除此错误并恢复我的“无错误”状态?

PS:v-calendar没有定义,是第三方导入的模块。

PS:这是我的“tsconfig.json”

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "strictPropertyInitialization": false,
    "strictNullChecks": false,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": ["webpack-env", "mocha", "chai"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
  "exclude": ["node_modules"]
}

【问题讨论】:

  • v-calendar 是在其他位置定义的文件吗?您可以使用相对路径来识别文件的位置。还是一个节点模块?
  • 不,没有定义,是第三方导入的lib

标签: typescript visual-studio-code tsconfig


【解决方案1】:

找不到模块“v-calendar”的声明文件。

使用以下内容创建文件external.d.ts

declare module 'v-calendar';

更多

Some docs on migration including declaring existing modules

【讨论】:

  • 链接已损坏。
猜你喜欢
  • 2016-06-30
  • 2020-04-01
  • 2017-11-05
  • 2019-08-08
  • 2018-05-04
  • 1970-01-01
  • 2019-03-06
  • 2017-02-13
  • 1970-01-01
相关资源
最近更新 更多