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 #97

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

metonym
Copy link
Collaborator

@metonym metonym commented Jan 26, 2025

Related: carbon-design-system/carbon-icons-svelte#203

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<CarbonPictogramProps, {}, 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.

@metonym metonym force-pushed the refactor-types-svelte-5 branch from 2b03091 to 36e54db Compare January 26, 2025 22:48
@metonym metonym merged commit 0c82406 into master Jan 26, 2025
3 checks passed
@metonym metonym deleted the refactor-types-svelte-5 branch January 26, 2025 22:53
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.

1 participant