From 51df3aee0da3ce0b8b938b8e0fafaba415d88fb2 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:31:05 +0200 Subject: [PATCH] docs(eslint-plugin): add docs for signal-store-feature-should-use-generic-type (#4521) --- .../rules/prefer-protected-state.md | 4 -- ...l-store-feature-should-use-generic-type.md | 62 +++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/projects/ngrx.io/content/guide/eslint-plugin/rules/prefer-protected-state.md b/projects/ngrx.io/content/guide/eslint-plugin/rules/prefer-protected-state.md index 32b04c059d..11ba7978bf 100644 --- a/projects/ngrx.io/content/guide/eslint-plugin/rules/prefer-protected-state.md +++ b/projects/ngrx.io/content/guide/eslint-plugin/rules/prefer-protected-state.md @@ -18,10 +18,8 @@ This rule ensures that state changes are only managed by the Signal Store to pre Examples of **incorrect** code for this rule: ```ts -// SUGGESTION ❗ const Store = signalStore( { protectedState: false }, - ~~~~~~~~~~~~~~~~~~~~~ [warning] withState({}), ); ``` @@ -29,14 +27,12 @@ const Store = signalStore( Examples of **correct** code for this rule: ```ts -// GOOD ✅ const Store = signalStore( withState({}), ); ``` ```ts -// GOOD ✅ const Store = signalStore( { protectedState: true }, withState({}), diff --git a/projects/ngrx.io/content/guide/eslint-plugin/rules/signal-store-feature-should-use-generic-type.md b/projects/ngrx.io/content/guide/eslint-plugin/rules/signal-store-feature-should-use-generic-type.md index db66dfcc38..1bd25d528f 100644 --- a/projects/ngrx.io/content/guide/eslint-plugin/rules/signal-store-feature-should-use-generic-type.md +++ b/projects/ngrx.io/content/guide/eslint-plugin/rules/signal-store-feature-should-use-generic-type.md @@ -10,3 +10,65 @@ A custom Signal Store feature that accepts an input should define a generic type + +## Rule Details + +This rule ensure that a Signal Store feature uses a generic type to define the feature state. + +Examples of **incorrect** code for this rule: + +```ts +const withY = () => signalStoreFeature( + { state: type<{ y: number }>() }, + withState({}) + ); +``` + +```ts +const withY = () => { + return signalStoreFeature( + type<{ state: { y: number } }>(), + withState({}) + ); +} +``` + +```ts +function withY() { + return signalStoreFeature( + type<{ state: { y: number } }>(), + withState({}) + ); +} +``` + +Examples of **correct** code for this rule: + +```ts +const withY = () => signalStoreFeature( + { state: type<{ y: Y }>() }, + withState({}) +); +``` + +```ts +const withY = <_>() => { + return signalStoreFeature( + type<{ state: { y: number } }>(), + withState({}) + ); +}; +``` + +```ts +function withY<_>() { + return signalStoreFeature( + { state: type<{ y: Y }>() }, + withState({}) + ); +} +``` + +## Further reading + +- [Known TypeScript Issues with Custom Store Features](guide/signals/signal-store/custom-store-features#known-typescript-issues)