簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM