add name types generator for ionicons and export them #1474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This has been bothering me for years. I used the suggestion in this issue. #1269
What has changed:
The
npm run build
script creates a type file after theionicons.json
file has been created.IoniconName
andIoniconSource
are the types created from the json file. These types are also exported from index.ts so as to be available without using node_modules/ionicons/dist.This change makes sure
name
is limited to actual available strings for icons.(Stencil example)
If you're using type checking, this would be valid
<ion-icon name="heart" size="large" slot="start"></ion-icon>
This would not be valid
<ion-icon name="not-an-ionicon" size="large" slot="start"></ion-icon>
This will be a breaking change for some because they will have explicitly defined the name as "string". Also it must override Ionic's version (if using), although it works fine with it.
How to test
Just follow the same directions as usual, the npm build script creates the types.
What I did not address: any related types that are currently
any
orstring
but did not fall within the scope of the feature request.Notes:
I used an .mjs script instead of a .ts script because there was a file called types.ts in scripts already.
I can definitely make it an actual .ts script with a different name, I had just been using this same script on my project and this was the quickest way.