Argument of type 'IconDefinition' is not assignable to parameter of type 'IconDefinitionOrPack'

让人想犯罪 __ 提交于 2020-01-13 11:32:46

问题


I'm using Angular 6 angular-starter and fontawesome, followed here on how to install fa to ng.

In my .ts looks like this:

import { library, dom } from '@fortawesome/fontawesome-svg-core';
import { faInstagram } from '@fortawesome/free-brands-svg-icons/faInstagram';
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';

public ngOnInit() {
    library.add(faInstagram);
    library.add(faLink);
    dom.watch();
}

Then in .html:

<fa-icon [icon]="['fab', 'instagram']"></fa-icon>

It works perfectly fine except for free brands, @fortawesome/free-brands-svg-icons. On build (npm start) it produces error/warning Argument of type 'IconDefinition' is not assignable to parameter of type 'IconDefinitionOrPack'. 'IconDefinition' is not assignable to type 'IconPack'. signature is missing in type 'IconDefinition'. on the 92% build but actually the build appears to be successful and the instagram icon shows up but I'm bothered because a red line below the code appears.

Can someone figure it out?

My package.json

"@fortawesome/angular-fontawesome": "^0.3.0",
"@fortawesome/fontawesome-svg-core": "^1.2.6",
"@fortawesome/free-brands-svg-icons": "^5.4.2",
"@fortawesome/free-solid-svg-icons": "^5.4.1",

回答1:


I'll mention a case with regular icons. Hope a similar approach will help you. You can just import the icon and then typecast it from IconDefinitionOrPack to IconDefinition while adding it to the library in your module constructor.

import { faTimesCircle, faCheckCircle } from '@fortawesome/free-regular-svg-icons';

Then while adding it in library typecast it

  export class AppModule {
    constructor() {
      library.add(faTable);
      library.add(faChartArea);
      library.add(faTachometerAlt);
      library.add(faTimesCircle as IconDefinition);
      library.add(faCheckCircle as IconDefinition);
    }
  }

In HTML,

<div class="col-md-6">
   <fa-icon [icon]="['far', 'check-circle']"></fa-icon>
   <span>Tax Info</span>
</div>


来源:https://stackoverflow.com/questions/53067036/argument-of-type-icondefinition-is-not-assignable-to-parameter-of-type-iconde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!