Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: IconPrefix should be typed to the specific icon group per package #20486

Open
2 tasks done
jernaumorat opened this issue Dec 3, 2024 · 1 comment
Open
2 tasks done
Assignees
Labels
bug needs-triage This bug needs to be confirmed

Comments

@jernaumorat
Copy link

jernaumorat commented Dec 3, 2024

Bug description

Hi all, I'm using @fortawesome/pro-duotone-svg-icons and @fortawesome/pro-duotone-svg-icons, which type exported icons as: type IconDefinition = { IconPrefix: 'far' | 'fad' | 'all-other-prefixes', ... }.
The "bug" is that each package should type the IconPrefix of its exports to only the prefix(es) supported by that package.
For example: @fortawesome/pro-duotone-svg-icons would export icons as type IconDefinition = { IconPrefix: 'fad', ... } explicitly, allowing compile-time checking of the icon class used.

I've tried using type declarations to override this typing, but it seems .d.ts files can only extend, not override types; so the only workaround would be to patch the package or perform a runtime check.

I would be happy to submit a PR for this myself but I'm unsure how as this affects Pro packs.

Font Awesome version

v6.6.0

Application and Operating System

  • TypeScript 5.4.5

Web bug report checklist

  • I have included a test case because my odds go way up that the team can fix this when I do
  • I have searched for existing issues and to the best of my knowledge this is not a duplicate
@jernaumorat jernaumorat added bug needs-triage This bug needs to be confirmed labels Dec 3, 2024
@jernaumorat
Copy link
Author

jernaumorat commented Dec 4, 2024

Looking at the free-regular-svg-icons typing, it seems this could be tricky/hacky without converting some of the fontawesome-common-types types to generics, as all icons across all packs are typed as the same IconDefinition. IconDefinition could be updated to type IconDefinition<T extends IconPrefix> = { prefix: T, ... }, but this would be a breaking change for consumers of @fort-awesome/fontawesome-common-types/IconDefinition

This could be done per package (without breaking common-types) by modifying IconDefinition:

import { IconDefinition as IconDefinitionBase } from 'fontawesome-common-types';
type IconDefinition = Omit<IconDefinitionBase, 'prefix'> & { prefix: 'far' };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage This bug needs to be confirmed
Projects
None yet
Development

No branches or pull requests

2 participants