Skip to content
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

docs(eslint-plugin): add docs for signal-store-feature-should-use-generic-type #4521

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ❗
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the referenced PR, this is removed to keep things consistent across the different rules.

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)