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

IconNameSubset duplicate name issue when using multiple icon sets #91

Closed
andy-polhill opened this issue Nov 27, 2020 · 12 comments · Fixed by #92 or #99
Closed

IconNameSubset duplicate name issue when using multiple icon sets #91

andy-polhill opened this issue Nov 27, 2020 · 12 comments · Fixed by #92 or #99

Comments

@andy-polhill
Copy link
Contributor

Hi, I believe we may have uncovered a potential breaking change while making a switch from 5.0.1 to 5.7.1, or alternatively it may be a misuse from our side.

In our project we have two sets of icons, icons and brand-icons. We isolate the two by running different svg-to-ts commands and generating separate files.

this change in v5.6.0 which introduced the IconNameSubset causes us a bit of an issue is we now have two exported types with the same name.

An unhandled exception occurred: projects/canopy/src/public-api.ts:25:1 - error TS2308: Module './lib/icon/index' has already exported a member named 'IconNameSubset'. Consider explicitly re-exporting to resolve the ambiguity.

There are probably a few things we could to fix it in our project, but I thought I would raise it here first to see if you think it had any validity as a bug. If so I'm happy to raise a PR to try and fix it.

One route would be to provide some kind of cli option to prefix the type in the same way it's done for the interface name. With a new option a breaking change could be avoided by deferring back to the default if no option is provided, the downside is that it might be a bit of an obscure option.

andy-polhill added a commit to lt83870/canopy that referenced this issue Nov 27, 2020
An issue was encountered while updating to the latest version of svg-to-ts, this commit pins it to a
specific version. An [issue](nivekcode/svg-to-ts#91) is raised against the
svg-to-ts repo, depending on the outcome we can either workaround it locally or help provide a fix.
andy-polhill added a commit to lt83870/canopy that referenced this issue Nov 27, 2020
An issue was encountered while updating to the latest version of svg-to-ts, this commit pins it to a
specific version. An [issue](nivekcode/svg-to-ts#91) is raised against the
svg-to-ts repo, depending on the outcome we can either workaround it locally or help provide a fix.
@andy-polhill andy-polhill changed the title Potential breaking change IconNameSubset duplicate name issue when using multiple icon sets Nov 27, 2020
andy-polhill added a commit to lt83870/canopy that referenced this issue Nov 27, 2020
An issue was encountered while updating to the latest version of svg-to-ts, this commit pins it to a
specific version. An [issue](nivekcode/svg-to-ts#91) is raised against the
svg-to-ts repo, depending on the outcome we can either workaround it locally or help provide a fix.
andy-polhill added a commit to lt83870/canopy that referenced this issue Nov 27, 2020
An issue was encountered while updating to the latest version of svg-to-ts, this commit pins it to a
specific version. An [issue](nivekcode/svg-to-ts#91) is raised against the
svg-to-ts repo, depending on the outcome we can either workaround it locally or help provide a fix.
@nivekcode
Copy link
Owner

Hi @thatguynamedandy

Thx a lot for reporting this issue. You are absolutely right. That's an error on our site. We didn't think of the combination of the helper type IconNameSubset in combination with multiple configurations.

So yes - we need to find a solution for this.

  1. We could prefix the helper type.
  2. We could add a flag to enable or disable it - So you could enable it per configuration.
  3. We would generate it only once into a shared folder or something.

The first option is the easiest to realize. But then you would have two helper types with different names that do the same. Disabling them would also be easy to realize. But then you need to be aware of enabling and disabling them. Generating them into a directory also would only be helpful in combination with option two. Thoughts?

I will also try to think again about the 3 options. Maybe there's an even better way.

andy-polhill added a commit to Legal-and-General/canopy that referenced this issue Nov 30, 2020
An issue was encountered while updating to the latest version of svg-to-ts, this commit pins it to a
specific version. An [issue](nivekcode/svg-to-ts#91) is raised against the
svg-to-ts repo, depending on the outcome we can either workaround it locally or help provide a fix.
@nivekcode
Copy link
Owner

After looking into it I think it makes sense to add a name prefix and also an option to disable it. So basically I would even switch to disable it by default which would be a breaking change.

@nivekcode
Copy link
Owner

I saw that you forked the repository. Are you already working on this or should I take a look?

@andy-polhill
Copy link
Contributor Author

I'll endeavour to take a look if thats ok?

I spent a bit of time looking into some options with typescript but didn't achieve too much. I was trying to focus on the ideal outcome and seeing how we might get there. I wondered if the ideal option would be this.

export type IconNameSubset<T extends Readonly<BrandIcon[]|Icon[]>> = T[number]['name'];

Which would allow us to use the same type for both Icons and BrandIcons (which in our case are the two types), meaning you could do this...

export type someIcons = IconNameSubset<[typeof myIconA, typeof myIconB]>; 
export type someBrandIcons = IconNameSubset<[typeof brandIconA, typeof brandIconB]>; 
export type thumbBrandIcons = IconNameSubset<[typeof myIconA, typeof brandIconA]>;  //no mixing of types

However I don't think there is anyway of doing this as the two icons are run on completely independent commands and I couldn't think of a clever typescript way of achieving that outcome.

So the option that you mentioned may be easiest, would it make sense to use the interfaceName as the prefix?

    export type ${interfaceName}NameSubset<T extends Readonly<${interfaceName}[]>> = T[number]['name'];

This way we wouldn't need to add any more options and it would still always export a uniquely named type helper. It would be a breaking change though.

Depending upon the appetite for breaking changes we could avoid it by adding an interim option prefixTypeHelper: boolean = false, which could be set as true to use the prefix. This would postpone a breaking change if you had more planned, and would only be needed for the minority who are affected by the issue (it would be a little smelly though)

andy-polhill added a commit to andy-polhill/svg-to-ts that referenced this issue Dec 2, 2020
BREAKING CHANGE: The `IconNameSubset` helper is now dynamically
generated based off of the `interfaceName` property. Any references to
this will need updating.

fix nivekcode#91
andy-polhill added a commit to andy-polhill/svg-to-ts that referenced this issue Dec 2, 2020
BREAKING CHANGE: The `IconNameSubset` helper is now dynamically
generated based off of the `interfaceName` property. Any references to
this will need updating.

fix nivekcode#91
@andy-polhill
Copy link
Contributor Author

Above is one possible approach, only raised as a draft more than happy to alter it.

@nivekcode
Copy link
Owner

nivekcode commented Dec 3, 2020

Hi @thatguynamedandy Thanks a lot for the explanation and the draft. I think this is the best solution. In case somebody needs to have the same Icons he could still do the following:

export type thumbBrandIcons = someIcons | someBrandIcons
I looked at the PR and it looks good to me. Also, I think breaking changes are not an issue as long as they are justified. So to me this already looks good. The release of this library is fully automated. Could you again commit with this commit message format:

fix(scope): message

BREAKING CHANGE: description

This should then automatically release v6.0.0.

@nivekcode
Copy link
Owner

Thx a lot for your effort 👍

@andy-polhill
Copy link
Contributor Author

Hi @kreuzerk I moved the PR out of draft, I think the commit message should match the syntax already, I didn't add the optional scope as I noticed it wasn't present in much of the history, but happy to add one.

@nivekcode
Copy link
Owner

Awesome. Thx a lot 👍 . Great work!

@nivekcode
Copy link
Owner

@all-contributors please add @thatguynamedandy for code, bugs, doc, ideas

@allcontributors
Copy link
Contributor

@kreuzerk

I've put up a pull request to add @thatguynamedandy! 🎉

andy-polhill added a commit to andy-polhill/svg-to-ts that referenced this issue Dec 3, 2020
BREAKING CHANGE: The `IconNameSubset` helper is now dynamically
generated based off of the `interfaceName` property. Any references to
this will need updating.

fix nivekcode#91
andy-polhill added a commit to andy-polhill/svg-to-ts that referenced this issue Dec 3, 2020
BREAKING CHANGE: The `IconNameSubset` helper is now dynamically
generated based off of the `interfaceName` property. Any references to
this will need updating.

fix nivekcode#91
@nivekcode nivekcode added the v6 label Dec 3, 2020
@nivekcode nivekcode linked a pull request Dec 6, 2020 that will close this issue
nivekcode pushed a commit that referenced this issue Dec 6, 2020
# [6.0.0](v5.7.1...v6.0.0) (2020-12-06)

### Bug Fixes

* 🐛 ensures name subset helper always has a unique name ([d1a5d69](d1a5d69)), closes [#91](#91)
* 🐛 start spinner on generation start ([6f34ab0](6f34ab0))

### Features

* 🎸 add verbose logging feature ([068eb1f](068eb1f))
* 🎸 logging steps with spinners ([55d7685](55d7685))

### BREAKING CHANGES

* The `IconNameSubset` helper is now dynamically
generated based off of the `interfaceName` property. Any references to
this will need updating.
@nivekcode
Copy link
Owner

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

andy-polhill added a commit to andy-polhill/canopy that referenced this issue Dec 7, 2020
There was a [slight issue](nivekcode/svg-to-ts#91) with a minor version
change in svg-to-ts. We temporarily pinned the version, but the issue has now been resolved.
andy-polhill added a commit to andy-polhill/canopy that referenced this issue Dec 7, 2020
There was a [slight issue](nivekcode/svg-to-ts#91) with a minor version
change in svg-to-ts. We temporarily pinned the version, but the issue has now been resolved.

fix Legal-and-General#88
elenagarrone pushed a commit to Legal-and-General/canopy that referenced this issue Dec 9, 2020
There was a [slight issue](nivekcode/svg-to-ts#91) with a minor version
change in svg-to-ts. We temporarily pinned the version, but the issue has now been resolved.

fix #88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants