简体   繁体   English

如何在具有类型的 TypeScript 项目中使用 Vue.use() javascript 插件

[英]How to Vue.use() a javascript plugin in a TypeScript project that does have typings

I am trying to use Semantic-UI-Vue in my vue project.我正在尝试在我的 vue 项目中使用Semantic-UI-Vue However, I am getting the following error when I try and do Vue.use(SuiVue) :但是,当我尝试执行Vue.use(SuiVue)时出现以下错误:

Argument of type 'typeof import("semantic-ui-vue")' is not assignable to parameter of type 'PluginObject<{}> | 'typeof import("semantic-ui-vue")' 类型的参数不可分配给 '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'." PluginFunction<{}>'。\\n 类型 'typeof import("semantic-ui-vue")' 不可分配给类型 'PluginFunction<{}>'。\\n 类型 'typeof import("semantic-ui-vue" )' 不匹配签名 '(Vue: VueConstructor, options?: {} | undefined): void'。"

I have created a .d.ts file that lets me import SuiVue:我创建了一个.d.ts文件,可以让我导入 SuiVue:

declare module 'semantic-ui-vue'{}

And I import it in my app.ts as:我将它导入到我的app.ts中:

import * as SuiVue from 'semantic-ui-vue';

What do I need to do to get this plugin to be usable in a typescript project without disabling global TypeScript settings like noImplicitAny ?我需要做什么才能让这个插件在打字稿项目中可用,而不禁用像noImplicitAny这样的全局打字稿设置?

Replace declare module 'semantic-ui-vue'{} with declare module 'semantic-ui-vue';declare module 'semantic-ui-vue'{}替换为declare module 'semantic-ui-vue';


declare module 'semantic-ui-vue'{} means the module have the type of an empty object {} . declare module 'semantic-ui-vue'{}表示模块具有空对象{}的类型。

declare module 'semantic-ui-vue'; means the module have the type any表示模块的类型为 any

see Shorthand ambient modules in https://www.typescriptlang.org/docs/handbook/modules.html请参阅https://www.typescriptlang.org/docs/handbook/modules.html 中的速记环境模块


As the OP has figured out, you need to change the import statement to import SuiVue from 'semantic-ui-vue';正如 OP 所发现的,您需要更改 import 语句以import SuiVue from 'semantic-ui-vue'; for it to work让它工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM