我正在尝试使用 Semantic-UI-Vue
在我的 vue 项目中。但是,当我尝试执行 Vue.use(SuiVue)
时出现以下错误:
Argument of type 'typeof import("semantic-ui-vue")' is not assignable to parameter of type 'PluginObject<{}> | PluginFunction<{}>'.\n Type 'typeof import("semantic-ui-vue")' is not assignable to type 'PluginFunction<{}>'.\n Type 'typeof import("semantic-ui-vue")' provides no match for the signature '(Vue: VueConstructor, options?: {} | undefined): void'."
我创建了一个 .d.ts
让我导入 SuiVue 的文件:
declare module 'semantic-ui-vue'{}
然后我将其导入到我的 app.ts
中作为:
import * as SuiVue from 'semantic-ui-vue';
在不禁用全局 TypeScript 设置(如 noImplicitAny
)的情况下,我需要做什么才能使此插件在 TypeScript 项目中可用? ?
最佳答案
将 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 SuiVue from 'semantic-ui-vue';
才能正常工作
关于javascript - 如何在具有类型的 TypeScript 项目中 Vue.use() 一个 javascript 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54357611/