![](/img/trans.png)
[英]Add plugin to vu Instance as "Vue.use()" without the root vue js file
[英]How to Vue.use() a javascript plugin in a TypeScript project that does have typings
我正在尝试在我的 vue 项目中使用Semantic-UI-Vue
。 但是,当我尝试执行Vue.use(SuiVue)
时出现以下错误:
'typeof import("semantic-ui-vue")' 类型的参数不可分配给 'PluginObject<{}> 类型的参数 | PluginFunction<{}>'。\\n 类型 'typeof import("semantic-ui-vue")' 不可分配给类型 'PluginFunction<{}>'。\\n 类型 'typeof import("semantic-ui-vue" )' 不匹配签名 '(Vue: VueConstructor, options?: {} | undefined): void'。"
我创建了一个.d.ts
文件,可以让我导入 SuiVue:
declare module 'semantic-ui-vue'{}
我将它导入到我的app.ts
中:
import * as SuiVue from 'semantic-ui-vue';
我需要做什么才能让这个插件在打字稿项目中可用,而不禁用像noImplicitAny
这样的全局打字稿设置?
将declare module 'semantic-ui-vue'{}
替换为declare module 'semantic-ui-vue';
declare module 'semantic-ui-vue'{}
表示模块具有空对象{}
的类型。
declare module 'semantic-ui-vue';
表示模块的类型为 any
请参阅https://www.typescriptlang.org/docs/handbook/modules.html 中的速记环境模块
正如 OP 所发现的,您需要更改 import 语句以import SuiVue from 'semantic-ui-vue';
让它工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.