Skip to content

Commit f471dc3

Browse files
committed
fix
1 parent 8600d27 commit f471dc3

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

documentation/docs/07-misc/06-v4-migration-guide.md

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,37 @@ dispatch('noArgument', 'surprise'); // error, cannot pass an argument
5656

5757
- `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))
5858

59-
```diff
60-
-const action: Action = (node, params) => { .. } // this is now an error if you use params in any way
61-
+const action: Action<HTMLElement, string> = (node, params) => { .. } // params is of type string
59+
```ts
60+
// @noErrors
61+
---const action: Action = (node, params) => { ... } // this is now an error if you use params in any way---
62+
+++const action: Action<HTMLElement, string> = (node, params) => { ... } // params is of type string+++
6263
```
6364

6465
- `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))
6566

66-
```diff
67+
```js
68+
// @noErrors
6769
// Example where this change reveals an actual bug
6870
onMount(
69-
- // someCleanup() not called because function handed to onMount is async
70-
- async () => {
71-
- const something = await foo();
72-
+ // someCleanup() is called because function handed to onMount is sync
73-
+ () => {
74-
+ foo().then(something => ..
75-
// ..
76-
return () => someCleanup();
77-
}
71+
--- // someCleanup() not called because function handed to onMount is async
72+
async () => {
73+
const something = await foo();---
74+
+++ // someCleanup() is called because function handed to onMount is sync
75+
() => {
76+
foo().then(something => {...});
77+
// ...
78+
return () => someCleanup();
79+
}
7880
);
7981
```
8082
8183
## Custom Elements with Svelte
8284
8385
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:
8486
85-
```diff
86-
-<svelte:options tag="my-component" />
87-
+<svelte:options customElement="my-component" />
87+
```svelte
88+
---<svelte:options tag="my-component" />---
89+
+++<svelte:options customElement="my-component" />+++
8890
```
8991
9092
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
9395
9496
`SvelteComponentTyped` is deprecated, as `SvelteComponent` now has all its typing capabilities. Replace all instances of `SvelteComponentTyped` with `SvelteComponent`.
9597
96-
```diff
97-
- import { SvelteComponentTyped } from 'svelte';
98-
+ import { SvelteComponent } from 'svelte';
98+
```js
99+
---import { SvelteComponentTyped } from 'svelte';---
100+
+++import { SvelteComponent } from 'svelte';+++
99101

100-
- export class Foo extends SvelteComponentTyped<{ aProp: string }> {}
101-
+ export class Foo extends SvelteComponent<{ aProp: string }> {}
102+
---export class Foo extends SvelteComponentTyped<{ aProp: string }> {}---
103+
+++export class Foo extends SvelteComponent<{ aProp: string }> {}+++
102104
```
103105
104106
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>`.
105107
106-
```diff
108+
```svelte
107109
<script>
108-
import ComponentA from './ComponentA.svelte';
109-
import ComponentB from './ComponentB.svelte';
110-
import { SvelteComponent } from 'svelte';
110+
import ComponentA from './ComponentA.svelte';
111+
import ComponentB from './ComponentB.svelte';
112+
import { SvelteComponent } from 'svelte';
111113

112-
- let component: typeof SvelteComponent;
113-
+ let component: typeof SvelteComponent<any>;
114+
let component: typeof SvelteComponent+++<any>+++;
114115

115-
function choseRandomly() {
116-
component = Math.random() > 0.5 ? ComponentA : ComponentB;
117-
}
116+
function choseRandomly() {
117+
component = Math.random() > 0.5 ? ComponentA : ComponentB;
118+
}
118119
</script>
119120

120121
<button on:click={choseRandomly}>random</button>
@@ -217,12 +218,13 @@ const { code } = await preprocess(
217218
218219
This could affect you for example if you are using `MDsveX` - in which case you should make sure it comes before any script or style preprocessor.
219220
220-
```diff
221+
```js
222+
// @noErrors
221223
preprocess: [
222-
- vitePreprocess(),
223-
- mdsvex(mdsvexConfig)
224-
+ mdsvex(mdsvexConfig),
225-
+ vitePreprocess()
224+
--- vitePreprocess(),
225+
mdsvex(mdsvexConfig)---
226+
+++ mdsvex(mdsvexConfig),
227+
vitePreprocess()+++
226228
]
227229
```
228230

0 commit comments

Comments
 (0)