- `Action` and `ActionReturn` have a default parameter type of `undefined` now, which means you need to type the generic if you want to specify that this action receives a parameter. The migration script will migrate this automatically ([#7442](https://github.com/sveltejs/svelte/pull/7442))
- `Action` and `ActionReturn` have a default parameter type of `undefined` now, which means you need to type the generic if you want to specify that this action receives a parameter. The migration script will migrate this automatically ([#7442](https://github.com/sveltejs/svelte/pull/7442))
```diff
```ts
-const action: Action = (node, params) => { .. } // this is now an error if you use params in any way
// @noErrors
+const action: Action<HTMLElement,string> = (node, params) => { .. } // params is of type string
---const action: Action = (node, params) => { ... } // this is now an error if you use params in any way---
+++const action: Action<HTMLElement,string> = (node, params) => { ... } // params is of type string+++
```
```
- `onMount` now shows a type error if you return a function asynchronously from it, because this is likely a bug in your code where you expect the callback to be called on destroy, which it will only do for synchronously returned functions ([#8136](https://github.com/sveltejs/svelte/issues/8136))
- `onMount` now shows a type error if you return a function asynchronously from it, because this is likely a bug in your code where you expect the callback to be called on destroy, which it will only do for synchronously returned functions ([#8136](https://github.com/sveltejs/svelte/issues/8136))
```diff
```js
// @noErrors
// Example where this change reveals an actual bug
// Example where this change reveals an actual bug
onMount(
onMount(
-// someCleanup() not called because function handed to onMount is async
--- // someCleanup() not called because function handed to onMount is async
- async () => {
async () => {
- const something = await foo();
const something = await foo();---
+// someCleanup() is called because function handed to onMount is sync
+++ // someCleanup() is called because function handed to onMount is sync
+ () => {
() => {
+ foo().then(something => ..
foo().then(something => {...});
// ..
// ...
return () => someCleanup();
return () => someCleanup();
}
}
);
);
```
```
@ -82,9 +84,9 @@ onMount(
The creation of custom elements with Svelte has been overhauled and significantly improved. The `tag` option is deprecated in favor of the new `customElement` option:
The creation of custom elements with Svelte has been overhauled and significantly improved. The `tag` option is deprecated in favor of the new `customElement` option:
This change was made to allow [more configurability](custom-elements-api#component-options) for advanced use cases. The migration script will adjust your code automatically. The update timing of properties has changed slightly as well. ([#8457](https://github.com/sveltejs/svelte/issues/8457))
This change was made to allow [more configurability](custom-elements-api#component-options) for advanced use cases. The migration script will adjust your code automatically. The update timing of properties has changed slightly as well. ([#8457](https://github.com/sveltejs/svelte/issues/8457))
@ -93,28 +95,27 @@ This change was made to allow [more configurability](custom-elements-api#compone
`SvelteComponentTyped` is deprecated, as `SvelteComponent` now has all its typing capabilities. Replace all instances of `SvelteComponentTyped` with `SvelteComponent`.
`SvelteComponentTyped` is deprecated, as `SvelteComponent` now has all its typing capabilities. Replace all instances of `SvelteComponentTyped` with `SvelteComponent`.
```diff
```js
-import { SvelteComponentTyped } from 'svelte';
---import { SvelteComponentTyped } from 'svelte';---
+ import { SvelteComponent } from 'svelte';
+++import { SvelteComponent } from 'svelte';+++
-export class Foo extends SvelteComponentTyped<{ aProp: string }> {}
---export class Foo extends SvelteComponentTyped<{ aProp: string }> {}---
+export class Foo extends SvelteComponent<{ aProp: string }> {}
+++export class Foo extends SvelteComponent<{ aProp: string }> {}+++
```
```
If you have used `SvelteComponent` as the component instance type previously, you may see a somewhat opaque type error now, which is solved by changing `: typeof SvelteComponent` to `: typeof SvelteComponent<any>`.
If you have used `SvelteComponent` as the component instance type previously, you may see a somewhat opaque type error now, which is solved by changing `: typeof SvelteComponent` to `: typeof SvelteComponent<any>`.