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

Allow a simple prop variable declaration to be treated the same as a rest declaration #9658

Closed
Thiagolino8 opened this issue Nov 26, 2023 · 1 comment

Comments

@Thiagolino8
Copy link

Describe the problem

Currently, when declaring props as a simple declaration, the following error is returned: $props() can only be used with an object destructuring pattern

But if the destructuring pattern is used with the rest pattern, the generated code is a simple declaration

let props = $.rest_props($$props, []);

Describe the proposed solution

Treat this let props = $props() in the same way as this let {...props} = $props()

Alternatives considered

Not doing it, although receiving an object as a return instead of having to adopt the rest pattern is more intuitive

Importance

nice to have

@bfanger
Copy link
Contributor

bfanger commented Dec 27, 2023

Guiding developers to use named props with destructuring has sereral advantages:

  • Self-documenting code: naming props explicity is a good idea:
    • Props are the public api of a component
    • Allows editors to show autocompletion for known props.
  • Less bikeshedding discusions about using props.foo vs { foo }

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

No branches or pull requests

2 participants