Skip to content

Add type parameter for Id in createEntityAdapter #2098

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

Closed
Matt-Ord opened this issue Mar 5, 2022 · 6 comments
Closed

Add type parameter for Id in createEntityAdapter #2098

Matt-Ord opened this issue Mar 5, 2022 · 6 comments

Comments

@Matt-Ord
Copy link
Contributor

Matt-Ord commented Mar 5, 2022

Currently createEntityAdapter provides no type checking for the id of an entity

This prevents type checking when using the selectors, and means that the return type of functions such as getAllIds returns EntityId[] rather than a type specific to the entity.

Introducing an (optional) type parameter for Id will solve all of these propblems, and also allow for the newtype pattern to ensure types between different adapters do not get mixed up

type MyIdType = string & { readonly __tag: unique symbol }
@markerikson
Copy link
Collaborator

Hmm. @phryneas , thoughts?

@Matt-Ord
Copy link
Contributor Author

Any updates on this - I should have time to make some changes to the pr this weekend if you decide this is something you want

@phryneas
Copy link
Member

Sorry, I have my wedding party coming up on saturday and don't really have the mental capacity to get deeper into this before that.

@Matt-Ord
Copy link
Contributor Author

Just thought I would drop another message to see what the status was with this - I'm happy to give more details of my use case if it would be helpful

@phryneas
Copy link
Member

I'll have time this friday.
Generally, something like this might be useful, but there is a very fine line balancing "adding additional generic parameters in many places" and "is the feature worth it" - since additional generic parameters become part of a contract we cannot change any more and have to support pretty much indefinitely.

@markerikson
Copy link
Collaborator

Available in the 2.0 betas.

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

Successfully merging a pull request may close this issue.

3 participants