typescript - 无法导入无类型的 npm 模块
问题描述
我添加paths
到baseUrl
我的tsconfig.json
{
"compilerOptions": {
"outDir": "./built/",
"sourceMap": true,
"baseUrl": ".",
"paths": {
"*": [ "./typings/*" ]
},
"strict": true,
"noImplicitReturns": true,
"module": "es2015",
"moduleResolution": "node",
"target": "es5"
},
"include": [
"./src/**/*"
]
}
我是 Typescript 的新手,我确实看过但无法解决我的问题。
我试着:
--index.ts
import * as VueGoogleMaps from "vue2-google-maps"
Vue.use(VueGoogleMaps, {
load: {
key: GMAPS_KEY,
libraries: 'places',
}
}
我不断收到错误:
TS2345: Argument of type 'typeof 'vue2-google-maps'' is not assignable to parameter of type 'PluginObject<any> | PluginFunction<any>'.
我尝试了一堆东西./typings/index.d.ts
但是我缺少基础知识,我知道VueGoogleMaps
应该有一种 PluginObject 类型,但我不知道声明它的语法。
我试过了:
declare module 'vue2-google-maps' {
import _Vue from 'vue'
import { PluginObject, PluginFunction } from "vue/types/plugin"
export default class GMaps<T> implements PluginObject<T> {
install(Vue: typeof _Vue, options?: T): void
}
}
任何帮助表示赞赏
解决方案
推荐阅读
- python - Python中多元正态变量的生成器
- html - 如何让我的页面上的此页脚与左右元素正确对齐?
- python - 在生成器的 finally 块中返回,隐藏异常
- laravel - 如果未验证新更新的电子邮件,则使用旧电子邮件登录
- azure - signin-oidc成功后如何获取访问令牌?
- python - Tensorflow1 concat 2D 张量与所有行排列
- python - 从脚本中运行时,Python distutils.core.run_setup 失败?
- oracle - 旧式外连接 (+) 不能与 ANSI 连接一起使用,Oracle 数据库错误代码 ORA-25156
- mysql - 使用 SELECT WHERE NULL 更新
- c++ - 从递归函数返回对象指针遇到访问冲突