Skip to content

(eslint-plugin): Propose updater-explicit-type-parameter ComponentStore rule #4754

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
1 of 2 tasks
LayZeeDK opened this issue Apr 11, 2025 · 0 comments
Open
1 of 2 tasks

Comments

@LayZeeDK
Copy link
Contributor

Which @ngrx/* package(s) are relevant/related to the feature request?

eslint-plugin

Information

I would like to suggest/contribute a ComponentStore ESLint rule. It would be an opt-in rule as it is a stylistic choices. What do you think?

updater-explicit-type-parameter

Updater should have a type parameter.

  • Type: suggestion
  • Fixable: No
  • Suggestion: Yes
  • Requires type checking: No
  • Configurable: No

Rule Details

To have consistent code, we should explicitly add a type parameter.

Examples of incorrect code for this rule:

Value parameter type

interface MoviesState {
  movies: Movie[];
}

class MoviesStore extends ComponentStore<MoviesState> {
  readonly addMovie = this.updater((state, movie: Movie): MoviesState => ({
                    // ⚠ no type parameter passed
    movies: [...state.movies, movie],
  }));
}

No value parameter type

interface MoviesState {
  movies: Movie[];
}

class MoviesStore extends ComponentStore<MoviesState> {
  readonly addMovie = this.updater((state, movie): MoviesState => ({
                    // ⚠ no type parameter passed
    movies: [...state.movies, movie],
  }));
}

Examples of correct code for this rule:

Value parameter type

interface MoviesState {
  movies: Movie[];
}

class MoviesStore extends ComponentStore<MoviesState> {
  readonly addMovie = this.updater<Movie>((state, movie: Movie): MoviesState => ({
                    // ✅ type parameter passed
    movies: [...state.movies, movie],
  }));
}

No value parameter type

interface MoviesState {
  movies: Movie[];
}

class MoviesStore extends ComponentStore<MoviesState> {
  readonly addMovie = this.updater<Movie>((state, movie): MoviesState => ({
                    // ✅ type parameter passed
    movies: [...state.movies, movie],
  }));
}

Describe any alternatives/workarounds you're currently using

Without a lint rule enforcing one style, a codebase could have different variations of updater type definitions.

I would be willing to submit a PR to fix this issue

  • Yes
  • No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants