-
-
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
Svelte 5: ComponentType
is still a constructor
#11472
Comments
The real shape of components is deliberately hidden. Doing something like this is prone to break because it's relying on private API. |
That would be cool for "higher order components". For example I created a dialog component that uses a bit of Inline JS to be available before the bundle loads (for progressive enhancement). However this requires having the same Id of the trigger. Currently you have to remember to pass the same id. With such API I could create a create dialog function that return the trigger and the dialog while also specifying the id prop by himself. |
Maybe this is the case starting in Svelte 5, but in Svelte 4 this API seems to be reasonably well documented.
Here’s my actual use case: Svelte 4, Svelte 5 (gross hack version) |
#11472 brought up a gap we have with the new API currently: There's no way to decorate a component right now. With the old class syntax this was straightforward because you would extend the class and for example modify the props on the way in. This adds `decorateComponent` to achieve the same.
Have one question about Svelte 5 and removal of constructor for the component. Today i export some of my components as isolated es modules that "anyone" can lazy load with import(...) and then call the constructor to initialize the component. Will this be breaking now 😰? |
Yes it would break when calling |
That would mean they need to install Svelte or I now need to wrap the mount myself, right? Oboy... |
If it's meant to be consumed standalone, then yes you need to wrap it yourself. |
i have question about `new Component and mount
open(Popup, { message: "It's a modal!" }); I wonder if my method is right. |
see my answer at flekschas/svelte-simple-modal#113 (comment) |
Describe the bug
In Svelte 5, components are no longer classes. However, the
ComponentType
type is still defined as a class constructor, not a function. This leads to situations where perfectly correct code is flagged as incorrect by the type checker.Reproduction
Here is a simple example of trying to “wrap” a component:
This code generates the TypeScript error
Value of type 'typeof MyComponent__SvelteComponent_' is not callable. Did you mean to include 'new'?
.Logs
No response
System Info
System: OS: macOS 14.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 111.14 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.0.0 - /opt/homebrew/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.5.1 - /opt/homebrew/bin/npm Browsers: Safari: 17.4.1 npmPackages: svelte: ^5.0.0-next.123 => 5.0.0-next.123
Severity
annoyance
The text was updated successfully, but these errors were encountered: