Skip to content

Rule to enforce type declaration of $state rune #1230

Open
@AntonioVentilii

Description

@AntonioVentilii

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions