Description
svelte 4 : stricter types for createEventDispatcher, Action , ActionReturn , and onMount
Codemod description
createEventDispatcher now supports specifying that a payload is optional, required, or non-existent, and the call sites are checked accordingly (#7224)
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)
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)
Examples
Note: The example section helps codemod champions identify all the transformation patterns that this codemod should handle. Repeat before/after snippets for every transformation example you can find.
Code before transformation
const action: Action<HTMLElement, string> = (node, params) => { .. }
async () => {
const something = await foo();
Code after transformation
const action: Action<HTMLElement, string> = (node, params) => { .. }
() => {
foo().then(something => ..
Applicability Criteria
Migration for Svelte 3->4