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

Only allow passing functions to lifecycle methods like onMount. #5529

Merged

Conversation

ehrencrona
Copy link
Contributor

Changing the parameter of onMount etc to take a function rather than any. I accidentally passed an evaluated function rather than the function itself in my TypeScript Sapper project and that gave a runtime rather than a compile-time error.

If I understand it right, types.d.ts is created from this file which in turn is used by the Sapper type definitions.

@j3rem1e
Copy link

j3rem1e commented Oct 15, 2020

We could also add that instead of "any", the onMount function should return void|()=>void

@ehrencrona
Copy link
Contributor Author

We could also add that instead of "any", the onMount function should return void|()=>void

The problem is that it risks breaking existing code. There will be no working code that passes in something else than a function, but there can easily be code that passes in a function with a return value.

@Conduitry Conduitry merged commit 4669047 into sveltejs:master Oct 22, 2020
@Conduitry
Copy link
Member

This has been released in 3.29.1, thanks!

hontas added a commit to hontas/svelte that referenced this pull request Oct 29, 2020
* upstream/master: (140 commits)
  support $$props and $$restProps for custom elements (sveltejs#5608)
  Bump eslint-config to 5.5.0 (sveltejs#5599)
  update changelog
  add Node and Element as known globals (sveltejs#5601)
  docs: fix a11y warning in media elements example (sveltejs#5606)
  Curly braces linting fixes (sveltejs#5585)
  refactor sourcemap and preprocessor tests (sveltejs#5583)
  -> v3.29.4
  fix code generation error with nullish coalescing operator and logical operators (sveltejs#5564)
  -> v3.29.3
  -> v3.29.2
  -> v3.29.1
  docs: fix a11y warning in media elements tutorial (sveltejs#5523)
  update changelog
  get context at start of {#if} update block instead of at the end (sveltejs#5531)
  update changelog
  only allow passing functions to lifecycle functions (sveltejs#5529)
  update changelog
  fix compiler hanging on <slot slot="..."> (sveltejs#5536)
  Add svelte@next caveat to bug report template (sveltejs#5561)
  ...
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants