【发布时间】:2021-01-30 23:40:16
【问题描述】:
我有一个基于 Vue 2.x CLI 的项目,它使用 typescript 和 vue 类组件运行。这里我想使用一个名为 vueisotope 的包,它没有类型定义文件。为了使它与打字稿一起工作,我更改了我的 tsconfig.json 以替代在“customTypes”文件夹中搜索 .d.ts 文件。我还创建了一个 customTypes/vueisotope/index.d.ts 文件并声明了该模块。在 Ubuntu 上该项目运行良好,但在 Windows 10 上我仍然收到以下错误:
15:24 Could not find a declaration file for module 'vueisotope'. 'node_modules/vueisotope/dist/vue_isotope.min.js' implicitly has an 'any' type.
Try npm install @types/vueisotope if it exists or add a new declaration (.d.ts) file containing declare module 'vueisotope';
我也尝试将该文件作为环境模块引用,但这也不起作用:
/// <reference path = "../customTypes/vueisotope/index.d.ts" />
我在这里做错了什么还是 Windows/TypeScript/IDE 问题?我怎样才能让它在 Windows 机器上工作?
我的 tsconfig:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"typeRoots": [
"./customTypes",
"./node_modules/@types"
],
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules",
"customTypes"
]
}
我的 index.d.ts:
declare module "vueisotope" {
}
【问题讨论】:
标签: windows typescript vue.js typescript-typings