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

RFC(@ngrx/signals): Add type of id as optional second type arg to withEntities<Entity,Id>() #4570

Open
1 of 2 tasks
ptandler opened this issue Oct 23, 2024 · 0 comments
Open
1 of 2 tasks

Comments

@ptandler
Copy link

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

signals

Information

The withEntities feature uses EntityId for the entities' id, which is defined as export type EntityId = string | number.

We have a use case where we need to narrow down the type of the id to (e.g.) UUID (or some other sub-type of string).

So I'd suggest adding a second optional type arg to withEntities() like this:

export declare function withEntities<Entity, Id extends EntityId = EntityId>(): SignalStoreFeature<EmptyFeatureResult, {
    state: EntityState<Entity, Id>;
    computed: EntityComputed<Entity, Id>;
    methods: {};
}>;

Describe any alternatives/workarounds you're currently using

At the moment we need to cast the id from EntityId to UUID:

signalStore(
    withEntities<V>(),
    withMethods((store) => ({
      allIds(): K[] {
        return store.ids() as K[];
      },
//...
)

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

  • Yes
  • No
@ptandler ptandler changed the title Add type of key as optional second type arg to withEntities<Entity,Id>() RFC(@ngrx/signals): Add type of key as optional second type arg to withEntities<Entity,Id>() Oct 23, 2024
@ptandler ptandler changed the title RFC(@ngrx/signals): Add type of key as optional second type arg to withEntities<Entity,Id>() RFC(@ngrx/signals): Add type of id as optional second type arg to withEntities<Entity,Id>() Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant