Skip to content

Commit 9a99554

Browse files
authored
breaking: remove Component type, keep using SvelteComponent instead (#9413)
I came to the conclusion that when we're making up arbitrary types, we might as well keep the old class. That way: - one less thing to worry about (language tools and other tooling basically can continue to spit out SvelteComponent ) - we can more clearly mark $set , the constructor etc as being deprecated and no longer functioning unless you use that legacy compatibility mode - much more ergonomic to type for the user: - const someInstance: SvelteComponent<..> instead of const someInstance: ReturnType<typeof Component<..>> - If you're using generics, you can do export class MyComponent<T> extends SvelteComponent<{ prop: T }> {} instead of having to type out the whole function in a way that I'm not even sure how to do with generics
1 parent 2ae9539 commit 9a99554

File tree

9 files changed

+166
-187
lines changed

9 files changed

+166
-187
lines changed

.changeset/small-papayas-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
breaking: remove Component type, keep using SvelteComponent instead

packages/svelte/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ await createBundle({
2727
[`${pkg.name}/animate`]: `${dir}/src/animate/public.d.ts`,
2828
[`${pkg.name}/compiler`]: `${dir}/src/compiler/index.js`,
2929
[`${pkg.name}/easing`]: `${dir}/src/easing/index.js`,
30-
[`${pkg.name}/legacy`]: `${dir}/src/legacy/public.d.ts`,
30+
[`${pkg.name}/legacy`]: `${dir}/src/legacy/legacy-client.js`,
3131
[`${pkg.name}/motion`]: `${dir}/src/motion/public.d.ts`,
3232
[`${pkg.name}/server`]: `${dir}/src/server/index.js`,
3333
[`${pkg.name}/store`]: `${dir}/src/store/public.d.ts`,

packages/svelte/src/internal/client/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ export function unwrap(value) {
30203020
* @template {Record<string, any>} Props
30213021
* @template {Record<string, any> | undefined} Exports
30223022
* @template {Record<string, any>} Events
3023-
* @param {import('../../main/public.js').Component<Props, Exports, Events>} component
3023+
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
30243024
* @param {{
30253025
* target: Node;
30263026
* props?: Props;
@@ -3139,7 +3139,7 @@ export function createRoot(component, options) {
31393139
* @template {Record<string, any>} Props
31403140
* @template {Record<string, any> | undefined} Exports
31413141
* @template {Record<string, any>} Events
3142-
* @param {import('../../main/public.js').Component<Props, Exports, Events>} component
3142+
* @param {import('../../main/public.js').SvelteComponent<Props, Events>} component
31433143
* @param {{
31443144
* target: Node;
31453145
* props?: Props;

packages/svelte/src/legacy/legacy-client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import * as $ from '../internal/index.js';
1111
* @template {Record<string, any>} Events
1212
* @template {Record<string, any>} Slots
1313
*
14-
* @param {import('./public.js').ComponentConstructorOptions<Props> & {
15-
* component: import('../main/public.js').Component<Props, Exports, Events, Slots>;
14+
* @param {import('../main/public.js').ComponentConstructorOptions<Props> & {
15+
* component: import('../main/public.js').SvelteComponent<Props, Events, Slots>;
1616
* immutable?: boolean;
1717
* recover?: false;
1818
* }} options
19-
* @returns {import('./public.js').SvelteComponent<Props & Exports, Events, Slots>}
19+
* @returns {import('../main/public.js').SvelteComponent<Props, Events, Slots> & Exports}
2020
*/
2121
export function createClassComponent(options) {
2222
// @ts-expect-error $$prop_def etc are not actually defined
@@ -33,8 +33,8 @@ export function createClassComponent(options) {
3333
* @template {Record<string, any>} Events
3434
* @template {Record<string, any>} Slots
3535
*
36-
* @param {import('../main/public.js').Component<Props, Exports, Events, Slots>} component
37-
* @returns {typeof import('./public.js').SvelteComponent<Props & Exports, Events, Slots>}
36+
* @param {import('../main/public.js').SvelteComponent<Props, Events, Slots>} component
37+
* @returns {typeof import('../main/public.js').SvelteComponent<Props, Events, Slots> & Exports}
3838
*/
3939
export function asClassComponent(component) {
4040
// @ts-expect-error $$prop_def etc are not actually defined
@@ -57,7 +57,7 @@ class Svelte4Component {
5757
#instance;
5858

5959
/**
60-
* @param {import('./public.js').ComponentConstructorOptions & {
60+
* @param {import('../main/public.js').ComponentConstructorOptions & {
6161
* component: any;
6262
* immutable?: boolean;
6363
* recover?: false;

packages/svelte/src/legacy/legacy-server.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { render } from '../internal/server/index.js';
66
export { createClassComponent };
77

88
/**
9-
* Takes the component function and returns a Svelte 4 compatible component constructor.
9+
* Takes a Svelte 5 component and returns a Svelte 4 compatible component constructor.
1010
*
1111
* @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5.
1212
*
@@ -15,8 +15,8 @@ export { createClassComponent };
1515
* @template {Record<string, any>} Events
1616
* @template {Record<string, any>} Slots
1717
*
18-
* @param {import('../main/public.js').Component<Props, Exports, Events, Slots>} component
19-
* @returns {typeof import('./public.js').SvelteComponent<Props & Exports, Events, Slots>}
18+
* @param {import('../main/public.js').SvelteComponent<Props, Events, Slots>} component
19+
* @returns {typeof import('../main/public.js').SvelteComponent<Props, Events, Slots> & Exports}
2020
*/
2121
export function asClassComponent(component) {
2222
const component_constructor = as_class_component(component);
@@ -30,8 +30,9 @@ export function asClassComponent(component) {
3030
html: result.html
3131
};
3232
};
33-
// @ts-expect-error this is present for SSR
33+
// this is present for SSR
3434
component_constructor.render = _render;
3535

36+
// @ts-ignore
3637
return component_constructor;
3738
}

packages/svelte/src/legacy/public.d.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

packages/svelte/src/main/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module '*.svelte' {
2-
export { Component as default } from 'svelte';
2+
export { SvelteComponent as default } from 'svelte';
33
}
44

55
/**

0 commit comments

Comments
 (0)