Skip to content

feat(entity): strengthen typing of getInitialState #4819

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

Merged
merged 7 commits into from
Jun 30, 2025

Conversation

timdeschryver
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #4422

When initializing an EntityAdapter and subsequently setting the initialState using ...adapter.getInitialState({ }), it is possible, given the current interface, to introduce unknown variables that do not conform to the user's specified state. This could result in bugs related to mistyped variable names, resulting in confusing user error scenarios.

What is the new behavior?

This small change modifies the interface to require that the input state S extends EntityState, requires that the additionalState state argument conforms to an Omit version of this S type, which removes the 'id' and 'entities' properties by way of keyof EntityState, and then finally, since the argument now already extends EntityState, we can now simply return S.

Does this PR introduce a breaking change?

[x] Yes
[ ] No

Other information

This reopens #4423 (with an update of the branch) - with the upcoming release this is a good timing imho.

Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for ngrx-io canceled.

Name Link
🔨 Latest commit c1892a4
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-io/deploys/686253967c59840008e5536c

Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for ngrx-site-v19 ready!

Name Link
🔨 Latest commit c1892a4
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-site-v19/deploys/6862539681fcc80008c074fd
😎 Deploy Preview https://deploy-preview-4819--ngrx-site-v19.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@timdeschryver timdeschryver force-pushed the feat/entity-strict-types branch from 04c78b4 to f1d182a Compare June 30, 2025 07:19
@timdeschryver timdeschryver merged commit bfb21c2 into main Jun 30, 2025
14 checks passed
@timdeschryver timdeschryver deleted the feat/entity-strict-types branch June 30, 2025 10:46
@GavynHolt
Copy link

Thanks very much for closing this out @timdeschryver!

@timdeschryver
Copy link
Member Author

Thank you for bringing this up and opening a PR @GavynHolt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NGRX Entity, Stronger Typing on getInitialState
4 participants