DeborahK / Angular-NgRx-GettingStarted

Materials for our Pluralsight course: Angular NgRx: Getting Started: http://bit.ly/AngularNgRx.
MIT License
545 stars 724 forks source link

Added return statement to updateProducts method #47

Closed nbhat000 closed 3 years ago

nbhat000 commented 3 years ago

When using the updateProducts method, I got the below error: Argument of type '(action: { product: Product; } & TypedAction<"[Product] Update Product">) => void' is not assignable to parameter of type '(value: { product: Product; } & TypedAction<"[Product] Update Product">, index: number) => ObservableInput<any>'.Type 'void' is not assignable to type 'ObservableInput<any>'.ts(2345)

Adding a return statement as shown in code fixed this

duncanhunter commented 3 years ago

Hi

Thank you for the PR and for thinking of others.

Not using the return keyword with effects is very common to keep them more readable and concise. I am unsure why you needed to do this to make it work but encourage you to experiment with your local code to make it work. Likely in other effects, we make in the course it is working for you?

This is more a JavaScript question as using an unbraced fat arrow function like this very common.

I would prefer not to change this for everyone as it is not the real solution for everyone.

nbhat000 commented 3 years ago

@duncanhunter thanks for the reply! I actually had to add this within all the concatMap's on mine to get rid of the error (add, update, delete). Not sure why that is. If it isn't a more common issue for others then feel free to close the PR. Thanks!

DeborahK commented 3 years ago

Interesting that you ran into this issue.

According to the JavaScript documentation on Arrow function expressions here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

The return statement is only required for multi-line arrow functions. The return should not be necessary in these examples.

Is it possible you have an eslint rule set for explicit-function-return-type that could be causing this?

I'm closing this for now, but will reopen later if necessary.