Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rule proposal: Allow only one return inside of the setup #1884

Open
@pikax

Description

Please describe what the rule should do:

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

defineComponent({
 setup(){
 // code
 If (something) {
 // do something
 return; // <- Should warn about this 
 }
 return { /* ... */ }
 }
});
defineComponent({
 setup(){
 // code
 
 If (something) {
 // do something
 return {
 other: 1
 }; // <-- Should warn about this 
 }
 
 return {
 // ...
 }
 }
})

Additional context

If we return multiple times on the setup typescript will infer the setup type to be possible all the returns, the only case where multiple returns might make sense if on SSR (to prevent reactive objects), but even in SSR I would not multiple return.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /