-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Feature request: Make SVG with JS packages resilient to multiple instances of fontawesome-common-types #16592
Comments
@devoto13 great write-up! Now, let's see if I can catch up to you on understanding the problem and proposed solution 😄 After looking at the demo repo you provided, it looks like one of these type-incompatibility scenarios could happen as easily as when a new FA release has more icons added (combined with the condition that two packages that depend on Have I understood that much right? If so, then yeah, I can imagine this being a problem that could come up often enough to be really annoying. Initially, I'd thought that, since When you suggest:
Could you clarify what you mean? By "core icons", do you mean something in Do you mean something like moving the type definitions for I looked through the demo code in the repo, but maybe my TypeScript knowledge is just too fuzzy to notice the key difference between the first and third commits in terms of making those two types independent from the core icons. I don't have any pushback about it at this point--I'm still just trying to catch up with you to understand the problem and proposed solution. |
Separately, if the problem has to do with FA versions getting out of sync between the dependencies of one package (like In other words, rather than making the packages resilient to multiple instances of Is there any compelling reason a developer might intend to use package versions that are out of sync in this way? Or would it (almost) always be the case that this drift would be a mistake or an oversight? Would it (almost) always be the case that getting the FA versions in sync would produce the equivalent intended results for the developer while also avoiding this type incompatibility problem? |
Yes, pretty much. Basically every time one updates an icon package, they have to also update With the proposed approach it is still not perfect as users still have to update to the latest
The key change is in fontawesome-common-types/index.d.ts. Before
This is not required, but can be done as a follow up. E.g. we can inline
It is indeed a possible solution. And normally user would want to have all these versions in sync. On the other hand it will require user to be more involved, especially with the current versioning... We can make In the original issue user didn't update FA package, but added another icon package with the newer version (without even thinking about it, just I'm also a bit biased here, because I want to get closer to solution for FortAwesome/angular-fontawesome#172 and FortAwesome/angular-fontawesome#230. |
Well, this particular relaxing in E.g. one has to do this:
instead of this:
The problem comes from the feature of TypeScript, where it simplifies types - microsoft/TypeScript#29729.
|
I'd be interested to hear from more TypeScript users on this. The in-editor completion seems to be the only possible objection here. Everything else about this change seems to be an overall net gain. I'm trying to think about how we can target some of our TS users directly without spamming a larger list. @mlwilkerson you have any thoughts? |
One way to avoid losing the completion may be to use LiteralUnion. I remember that this approach had some tricky corner cases and is essentially a hack. I bit overloaded at work these days, but I'll try to squeeze some time in the next week or two to experiment with it and see if it will work here. |
Noting this issue: FortAwesome/Font-Awesome#16592
Hey @robmadole @mlwilkerson, There was a new problem caused by this issue reported recently in FortAwesome/angular-fontawesome#125 (comment). The problem is that the user used the SVG Core 1.3.x line with the icon packs of the FontAwesome 5, which are incompatible as shown by this minimal reproduction. As we're not able to find a feasible solution to support multiple versions of the Please consider aligning the versions of If we do this and also specify the fixed version of the The current situation where icon packages, common types, and SVG core have their own version makes it very hard to explain to the user what they need to do to solve the issue and in some cases makes it even impossible because of dependencies like I expect that this will become a very common issue for all TypeScript users moving forward specifically because of the I think we should publish |
Thank you, @devoto13. This seems reasonable to me too. I did spend some time investigating a related issue recently for someone facing this very challenge--the root cause of which had to do with the version of I've raised the concern internally as well, intending to get a plan in place for resolution. |
@devoto13 yep, I agree with @mlwilkerson. Your plan sounds correct and getting this fixed is high on the priority list. This is a mess and we'll look to get is solved as soon as we can. This will just continue to generate heartache and work for everyone. |
I'm going to close this issue as the above solution has been implemented. |
Is your feature request related to a problem? Please describe.
The problem was reported in FortAwesome/angular-fontawesome#125. Basically when users update icon package, but not
fontawesome-svg-core
package, they end up with the cryptic error message:And no simple way to solve it without dirty hacking with package manager and lock files.
This repository provides and example of how this happens (steps 1 and 2).
Describe the solution you'd like
Make
IconDefinition
andIconPack
independent from the core icons, so even if there are multiple instances offontawesome-common-types
package, the types are still assignable to each other because of duck typing.This change should not cause any loose of type safety as types are loosened on the definition side (which users normally don't use). The only place where completion is lost is when passing
IconLookup
to theicon()
function, becauseIconLookup
type is completely covered byIconDefinition
and therefore completely erased. I've discovered this during late testing and this is serious problem. But I'll post this issue anyways just to start a discussion around the problem. Maybe we should just accept this tradeoff... Or deprecateIconLookup
in favour of[IconPrefix, IconName]
syntax, which will still have completion.This change also makes it easier for users to define custom icons as there is no need to do any casts on definition side. E.g.
becomes
The only breaking change is that
IconDefinition
is no longer assignable toIconLookup
, which continues to use type unions for core icon and package names to provide completion on the usage site. This also makes updated icons/packages incompatible with not updated versions offontawesome-svg-core
, but this is more or less how it is today with FortAwesome/angular-fontawesome#125. Just that it will affect more people during the migration phase.See step 3 in the repository for the reference implementation of this feature.
Describe alternatives you've considered
fontawesome-common-types
package a peer dependency offontawesome-svg-core
and all*-svg-icons
packages to ensure that there is only one instance offontawesome-common-types
is installed. While this solves the problem, it requires extra effort and cognitive effort to maintain correct version and makes installation of FA even more complex.IconName
andIconPack
types by relying on TypeScript's declaration merging as shown in https://github.com/devoto13/fa-icons-merge. This is ultimately more complex and more disruptive solution, but has an added benefit that custom icons are supported and type check. Another issue @robmadole pointed in the private chat is that some people rely on completion to discover icons and with this approach only imported icons will be available in completion list.Additional context
Add any other context or screenshots about the feature request here.
Feature request checklist
Feature request: moar cowbell
)The text was updated successfully, but these errors were encountered: