-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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] add convenience types ComponentType and ComponentProps #6770
[feat] add convenience types ComponentType and ComponentProps #6770
Conversation
Eases typing "this is a variable that expects a Svelte component constructor (of a certain shape)". Removes the need for SvelteComponentTyped to be an extra type so it can be deprecated in v4 and removed in v5, and SvelteComponent(Dev) can receive the same generic typings as SvelteComponetTyped in v4.
Seems we need to bump the TypeScript version as it's too old to use the new |
I ended up bumping TS, acknowledging the fact that it may introduce accidentally adding type syntax later that is incompatible with TS 3.7 . Doing so technically is a breaking change, although I doubt that anyone is using a TS version this old, especially since everyone using TS with Svelte is required to use a newer version of TS. But because it's a breaking change, I decided to add a short script which rewrites the new type syntax to something valid in 3.7 . @Conduitry hope this is okay for you. |
@dummdidumm Required by what? SvelteKit? Other tooling? Is this a breaking change only insofar as someone might be manually interacting with the types using an old version of the TS compiler, separately from what any of the official tooling is already doing? |
It's a breaking change for everyone who uses an old TS version which does not understand the |
I updated the PR and adjusted the code. I switched out @ivanhofer @ignatiusmb could you have a look at this? More specifically:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice additions of useful type helpers.
The tsd.js
is a smart way to bypass the failing types 👏
@@ -128,7 +128,7 @@ export interface SvelteComponentDev { | |||
$destroy(): void; | |||
[accessor: string]: any; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file exports an interface SvelteComponentDev
and a class with the same name. The types of the interface and the class don't match. It was not added in this PR but I find it confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not part of this PR but wouldn't it be better to combine SvelteComponentDev
and SvelteComponentTyped
. Currently SvelteComponentTyped
is just SvelteComponentDev
with some generics that all contain default parameters. When not adding any generics this should result into the same type as SvelteComponentDev
Co-authored-by: Hofer Ivan <[email protected]>
Co-authored-by: Hofer Ivan <[email protected]>
Co-authored-by: Hofer Ivan <[email protected]>
Co-authored-by: Hofer Ivan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a nice addition to the Svelte + TS integration when it gets in!
Co-authored-by: Ignatius Bagus <[email protected]>
Co-authored-by: Ignatius Bagus <[email protected]>
Co-authored-by: Ignatius Bagus <[email protected]>
…dummdidumm/svelte into sveltecomponentconstructor-type
Co-authored-by: Ignatius Bagus <[email protected]>
Eases typing "this is a variable that expects a Svelte component constructor (of a certain shape)". Removes the need for SvelteComponentTyped to be an extra type so it can be deprecated in v4 and removed in v5, and SvelteComponent(Dev) can receive the same generic typings as SvelteComponetTyped in v4.
Also add
ComponentProps
to get the props a component expects (fixes #7584)Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint