Skip to content

Commit

Permalink
docs(eslint-plugin): add docs for signal-store-feature-should-use-gen…
Browse files Browse the repository at this point in the history
…eric-type (#4521)
  • Loading branch information
timdeschryver authored Sep 16, 2024
1 parent 21fe84b commit 51df3ae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ 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({}),
);
```

Examples of **correct** code for this rule:

```ts
// GOOD ✅
const Store = signalStore(
withState({}),
);
```

```ts
// GOOD ✅
const Store = signalStore(
{ protectedState: true },
withState({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,65 @@ A custom Signal Store feature that accepts an input should define a generic type

<!-- Everything above this generated, do not edit -->
<!-- MANUAL-DOC:START -->

## 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 = <Y>() => 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)

0 comments on commit 51df3ae

Please sign in to comment.