Skip to content

Rule to enforce type declaration of $state rune #1230

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

Open
AntonioVentilii opened this issue May 19, 2025 · 0 comments
Open

Rule to enforce type declaration of $state rune #1230

AntonioVentilii opened this issue May 19, 2025 · 0 comments
Labels
enhancement New feature or request new rule

Comments

@AntonioVentilii
Copy link

Motivation

Is there a rule that enforces the declaration of the types for $state? If not, is it worth doing?

Description

For consistency, we could have a rule similar to prefer-reduce-type-parameter, that clearly enforces where to define the type of a $state variable.

Examples

<script>

  // BAD
  let title: string | undefined = $state();
  let data: { value?: number } = $state({})
  
  // GOOD
  let title = $state<string | undefined>();
  let data = $state<{ value?: number }>({});
  
  // UNCHANGED
  let label = $state(0)

</script>

Additional comments

No response

@AntonioVentilii AntonioVentilii added enhancement New feature or request new rule labels May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

No branches or pull requests

1 participant