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

fix(data): make entity param partial when is not optimistic #2899

Merged

Conversation

yharaskrik
Copy link
Contributor

  • Make the entity: T parameter for the NgRx Data .add command partial when isOptimistic: false since in some cases the PK will be created on the server

Closes #2870

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] 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?

Currently NgRx Data allows the primary key to not be passed into the .add() function for an entity but the typings do not allow for that as they expect T

Closes #2870

What is the new behavior?

Change T to be Partial<T> so that functionality is represented in the types. The full object may not be available as create time if isOptimistic is false.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

- Make the entity: T parameter for the NgRx Data .add command partial when isOptimistic: false since in some cases the PK will be created on the server

Closes ngrx#2870
@yharaskrik
Copy link
Contributor Author

Workflow failed and I am not entirely sure why as I do not know much about github actions, can anyone point me in the direction of what I need to do to let the workflow run?

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 29, 2021

Preview docs changes for 6d7281b at https://previews.ngrx.io/pr2899-6d7281b6/

@brandonroberts
Copy link
Member

The labeler action is a false positive due to permissions. I've disabled it for now

@yharaskrik
Copy link
Contributor Author

Gotcha! Thank you!

@timdeschryver timdeschryver merged commit bb70e6c into ngrx:master Jan 30, 2021
@timdeschryver
Copy link
Member

Thanks @yharaskrik

@yharaskrik
Copy link
Contributor Author

You are welcome!

@yharaskrik
Copy link
Contributor Author

There is a bug in this PR I just found while writing the demo app for ngrx data.

this.storyDataService.add(story, { isOptimistic: false });

This will error with:

TS2322: Type 'false' is not assignable to type 'true'.  entity-collection-service-base.ts(146, 60): The expected type comes from property 'isOptimistic' which is declared here on type 'Pick<EntityActionOptions, "correlationId" | "mergeStrategy" | "tag" | "error" | "skip"> & { isOptimistic: true; }'

The function overload for the Partial<T> is above the original implementation so I think TS is seeing it first (since options is supplied) and is comparing isOptimistic: false to isOptimistic: true.

Not sure how exactly to type this correctly, I wonder why TS doesn't look at the second function overload. I will read more into function overloading to see what can be done about this.

@yharaskrik
Copy link
Contributor Author

Solved in: #2906

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