首页 > 解决方案 > 使用 Font Awesome 和 Vue 的 Typescript 构建错误

问题描述

我按照字体真棒网站上的说明在 Vue 中设置它们。在我的 main.ts 文件中,即使图标工作正常,我也会收到打字稿错误。

FunctionalComponentOptions 类型的参数

错误发生在 FontAwesomeIcon 上的这一行

Vue.component('font-awesome-icon', FontAwesomeIcon)

错误是“FunctionalComponentOptions,PropsDefinition>>”类型的参数不可分配给“ComponentOptions,DefaultMethods,DefaultComputed,PropsDefinition>,Record>”类型的参数。属性“渲染”的类型不兼容。

这是因为这个 index.d.ts 文件而发生的。如果我将它更改为任何它会工作。

declare module '@fortawesome/vue-fontawesome' {
  import { FunctionalComponentOptions } from 'vue'
  export const FontAwesomeIcon: FunctionalComponentOptions
  export const FontAwesomeLayers: FunctionalComponentOptions
  export const FontAwesomeLayersText: FunctionalComponentOptions
}

即使我使用来自(https://fontawesome.com/how-to-use/on-the-web/using-with/vuejs)的所有相同代码,我仍然会收到错误消息。

提前感谢您的帮助。

标签: typescriptvue.jsvuejs2font-awesome

解决方案


推荐阅读