Skip to content
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

[codemod request] svelte 4 : stricter types for createEventDispatcher, Action , ActionReturn , and onMount #772

Closed
arshcodemod opened this issue May 30, 2024 · 0 comments

Comments

@arshcodemod
Copy link
Contributor

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

Additional context or links

Migration Guide for Svelte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant