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

feat(component-store): accept error type in tapResponse #3056

Conversation

markostanimirovic
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?

The input argument of tapResponse error callback cannot be typed directly.

Closes #3051

What is the new behavior?

The input argument of tapResponse error callback can be typed directly:

tapResponse(
  () => {},
  (error: { message: string }) => console.error(error.message),
),

If not passed, the type of error will be unknown, just like the current tapResponse implementation.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jun 28, 2021

Preview docs changes for b07fe7f at https://previews.ngrx.io/pr3056-b07fe7f7/

@markostanimirovic markostanimirovic force-pushed the feat/component-store/tap-response-error branch from f19ef15 to b07fe7f Compare June 29, 2021 09:42
@timdeschryver timdeschryver changed the title feat(component-store): add ability for tapResponse to accept error type feat(component-store): accept error type in tapResponse Jun 29, 2021
@timdeschryver timdeschryver merged commit 61e1963 into ngrx:master Jun 29, 2021
@fgoulet
Copy link

fgoulet commented Jul 9, 2021

With this change, my code does not compile anymore and I don't understand how to fix it.

TS2345: Argument of type '(error: HttpErrorResponse) => void' is not assignable to parameter of type '<E = unknown>(error: E) => void'.   Types of parameters 'error' and 'error' are incompatible.     Type 'E' is not assignable to type 'HttpErrorResponse'.

     tapResponse(
            (newEquipmentItem) => {
               ....
            },
            (error: HttpErrorResponse) => {
             ....
            }
    )

@markostanimirovic
Copy link
Member Author

Thanks for reporting this @fgoulet.

It compiles in ngrx/platform repo because noStrictGenericChecks is set to true 🤦‍♂️

I'll raise the fix PR.

@brandonroberts
Copy link
Member

We should update that strict check in the repo also if Angular's default is more strict, so we're on the same baseline at least.

brandonroberts pushed a commit that referenced this pull request Jul 12, 2021
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 this pull request may close these issues.

@ngrx/component-store: add ability for tapResponse to accept error type
5 participants