FontAwesome 6 with Angular 18: Argument of type ‘IconDefinition’ is not assignable to parameter of type ‘IconName | IconLookup’

I have updated my Angular project from 17 to 18 and also updated FontAwesome to 6.6.0 and @fortawesome/angular-fontawesome to 0.15.0. I’ve checked the package-lock.json and all FontAwesome packages use the same version.

As per the @fortawesome/angular-fontawesome upgrade instructions I moved the type imports from @fortawesome/fontawesome-svg-core to @fortawesome/angular-fontawesome but I still get the following error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'.
Type 'IconDefinition' is not assignable to type 'IconLookup'.
Types of property 'prefix' are incompatible.
Type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/angular-fontawesome/types").IconPrefix' is not assignable to type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/fontawesome-common-types/index").IconPrefix'.
Type 'string & {}' is not assignable to type 'IconPrefix'. [plugin angular-compiler]
projects/material-lib/src/lib/util/register-icons.class.ts:43:20:
43return iconFunc(icon).html.join('');
~~~~
[ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'. [plugin angular-compiler]
projects/material-lib/src/lib/util/register-icons.class.ts:47:54:
47 │ ...n sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join(''));
~~~~
</code>
<code>✘ [ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'. Type 'IconDefinition' is not assignable to type 'IconLookup'. Types of property 'prefix' are incompatible. Type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/angular-fontawesome/types").IconPrefix' is not assignable to type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/fontawesome-common-types/index").IconPrefix'. Type 'string & {}' is not assignable to type 'IconPrefix'. [plugin angular-compiler] projects/material-lib/src/lib/util/register-icons.class.ts:43:20: 43 │ return iconFunc(icon).html.join(''); ╵ ~~~~ ✘ [ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'. [plugin angular-compiler] projects/material-lib/src/lib/util/register-icons.class.ts:47:54: 47 │ ...n sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join('')); ╵ ~~~~ </code>
✘ [ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'.
  Type 'IconDefinition' is not assignable to type 'IconLookup'.
    Types of property 'prefix' are incompatible.
      Type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/angular-fontawesome/types").IconPrefix' is not assignable to type 'import("D:/Project/Frontend/OAKKPortal/OAKKPortal/node_modules/@fortawesome/fontawesome-common-types/index").IconPrefix'.
        Type 'string & {}' is not assignable to type 'IconPrefix'. [plugin angular-compiler]

    projects/material-lib/src/lib/util/register-icons.class.ts:43:20:
      43 │     return iconFunc(icon).html.join('');
         ╵                     ~~~~


✘ [ERROR] TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconName | IconLookup'. [plugin angular-compiler]

    projects/material-lib/src/lib/util/register-icons.class.ts:47:54:
      47 │ ...n sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join(''));
         ╵                                                 ~~~~

The relevant code that fails to compile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import {
FaIconLibrary,
IconDefinition,
IconName,
IconPrefix,
} from '@fortawesome/angular-fontawesome';
import { icon as iconFunc } from '@fortawesome/fontawesome-svg-core';
export class RegisterFontIcons {
public static registerMaterialIcons(iconRegistry: MatIconRegistry) {
// Register the material icon styles
iconRegistry.registerFontClassAlias(
'outlined',
'mat-ligature-font material-icons material-icons-outlined',
);
}
public static registerFontAwesomIcons(iconRegistry: MatIconRegistry) {
// Set default font set to Font Awesome Solid icons for non-SVG icons
iconRegistry.setDefaultFontSetClass('fa-solid');
}
public static registerFontAwesomSvgIcons(
iconRegistry: MatIconRegistry,
sanitizer: DomSanitizer,
icons: IconDefinition[],
) {
icons.forEach((icon: IconDefinition) => {
// console.log(icon.prefix, icon.iconName);
const svg: SafeHtml = RegisterFontIcons.getLiteralSafeSvg(sanitizer, icon);
if (icon.prefix === 'fas') {
iconRegistry.addSvgIconLiteral(icon.iconName, svg);
} else {
// Only use a namespace for the non-solid icons
iconRegistry.addSvgIconLiteralInNamespace(icon.prefix, icon.iconName, svg);
}
});
}
public static getLiteralSvg(icon: IconDefinition): string {
return iconFunc(icon).html.join('');
}
public static getLiteralSafeSvg(sanitizer: DomSanitizer, icon: IconDefinition): SafeHtml {
return sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join(''));
}
public static getFontAwesomeIcon(
faIconLibrary: FaIconLibrary,
prefix: IconPrefix,
name: IconName,
): IconDefinition {
return faIconLibrary.getIconDefinition(prefix, name);
}
}
</code>
<code>import { MatIconRegistry } from '@angular/material/icon'; import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { FaIconLibrary, IconDefinition, IconName, IconPrefix, } from '@fortawesome/angular-fontawesome'; import { icon as iconFunc } from '@fortawesome/fontawesome-svg-core'; export class RegisterFontIcons { public static registerMaterialIcons(iconRegistry: MatIconRegistry) { // Register the material icon styles iconRegistry.registerFontClassAlias( 'outlined', 'mat-ligature-font material-icons material-icons-outlined', ); } public static registerFontAwesomIcons(iconRegistry: MatIconRegistry) { // Set default font set to Font Awesome Solid icons for non-SVG icons iconRegistry.setDefaultFontSetClass('fa-solid'); } public static registerFontAwesomSvgIcons( iconRegistry: MatIconRegistry, sanitizer: DomSanitizer, icons: IconDefinition[], ) { icons.forEach((icon: IconDefinition) => { // console.log(icon.prefix, icon.iconName); const svg: SafeHtml = RegisterFontIcons.getLiteralSafeSvg(sanitizer, icon); if (icon.prefix === 'fas') { iconRegistry.addSvgIconLiteral(icon.iconName, svg); } else { // Only use a namespace for the non-solid icons iconRegistry.addSvgIconLiteralInNamespace(icon.prefix, icon.iconName, svg); } }); } public static getLiteralSvg(icon: IconDefinition): string { return iconFunc(icon).html.join(''); } public static getLiteralSafeSvg(sanitizer: DomSanitizer, icon: IconDefinition): SafeHtml { return sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join('')); } public static getFontAwesomeIcon( faIconLibrary: FaIconLibrary, prefix: IconPrefix, name: IconName, ): IconDefinition { return faIconLibrary.getIconDefinition(prefix, name); } } </code>
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import {
  FaIconLibrary,
  IconDefinition,
  IconName,
  IconPrefix,
} from '@fortawesome/angular-fontawesome';
import { icon as iconFunc } from '@fortawesome/fontawesome-svg-core';

export class RegisterFontIcons {
  public static registerMaterialIcons(iconRegistry: MatIconRegistry) {
    // Register the material icon styles
    iconRegistry.registerFontClassAlias(
      'outlined',
      'mat-ligature-font material-icons material-icons-outlined',
    );
  }

  public static registerFontAwesomIcons(iconRegistry: MatIconRegistry) {
    // Set default font set to Font Awesome Solid icons for non-SVG icons
    iconRegistry.setDefaultFontSetClass('fa-solid');
  }

  public static registerFontAwesomSvgIcons(
    iconRegistry: MatIconRegistry,
    sanitizer: DomSanitizer,
    icons: IconDefinition[],
  ) {
    icons.forEach((icon: IconDefinition) => {
      // console.log(icon.prefix, icon.iconName);
      const svg: SafeHtml = RegisterFontIcons.getLiteralSafeSvg(sanitizer, icon);
      if (icon.prefix === 'fas') {
        iconRegistry.addSvgIconLiteral(icon.iconName, svg);
      } else {
        // Only use a namespace for the non-solid icons
        iconRegistry.addSvgIconLiteralInNamespace(icon.prefix, icon.iconName, svg);
      }
    });
  }

  public static getLiteralSvg(icon: IconDefinition): string {
    return iconFunc(icon).html.join('');
  }

  public static getLiteralSafeSvg(sanitizer: DomSanitizer, icon: IconDefinition): SafeHtml {
    return sanitizer.bypassSecurityTrustHtml(iconFunc(icon).html.join(''));
  }

  public static getFontAwesomeIcon(
    faIconLibrary: FaIconLibrary,
    prefix: IconPrefix,
    name: IconName,
  ): IconDefinition {
    return faIconLibrary.getIconDefinition(prefix, name);
  }
}

The functions that fail are getLiteralSvg and getLiteralSafeSvg.

Any ideas on how to solve this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật