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

feat(types)!: use Component type for type definitions #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

metonym
Copy link
Collaborator

@metonym metonym commented Dec 27, 2024

Closes #201

Currently, the generated type definitions use SvelteComponentTyped with declare class ... for icon type definitions.

  • SvelteComponentTyped was deprecated in Svelte 4 and will be removed in a future major Svelte release.
  • declare class is no longer valid in Svelte 5 since components are no longer classes.

This PR implements the following:

  • Replace SvelteComponentTyped with the officially recommended Component utility type exported by Svelte.

Breaking Changes

  • TypeScript definitions are no longer compatible with Svelte 3. Note that the library will still work with Svelte 3; only types will be broken.
    • You will experience the following TypeScript error: Argument of type 'Component<CarbonIconProps, {}, string>' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.
    • This is likely an acceptable trade-off since the last Svelte 3 version was published two years ago. However, the latest Svelte 3 still (expectedly) has a high number of weekly downloads. This is acceptable since the upgrade path is relatively smooth; simply upgrading to Svelte 4 would resolve the type errors As of this writing:
    • Svelte 5: ~200k weekly downloads.
    • Svelte 4: ~100k
    • Svelte 3: ~100k
  • Exported CarbonIcon class is removed.
  • Exported CarbonIconProps type is preserved, but the underlying type has been reworked to properly extend SVG "rest props".

Additional Notes

  • Interestingly, usage of ComponentProps<typeof Icon> does not work as expected in Svelte 4. This indicates the value in preserving the exported CarbonIconProps type.
  • This library is compatible with Svelte 5 but cannot be used in Runes-only mode since it still uses $$restProps to forward props down to the underlying svg element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icon Typing is not Compatible with Svelte 5
1 participant