Platform: props doesn't accept HttpErrorResponse

Created on 22 Jan 2021  路  5Comments  路  Source: ngrx/platform

Minimal reproduction of the bug/regression with instructions:

I want to pass the HttpError through an action and so I do the following:

export const someFail = createAction(
  '[Feature] Some fail',
  props<HttpErrorResponse>(),
);

... however it doesn't compile:

Captura de Tela 2021-01-21 a虁s 22 03 14
Captura de Tela 2021-01-21 a虁s 22 03 51

Expected behavior:

props accept HttpErrorResponse.

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

Ngrx 10, Angular 11.

Other information:

I would be willing to submit a PR to fix this issue

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

Store

Most helpful comment

Thanks @markostanimirovic 馃憤

I wonder if we could make it clearer in the docs, e.g. don't do this (code example) and do with a prop name instead (code example).

All 5 comments

@dev054
HttpErrorResponse extends HttpResponseBase:

export abstract class HttpResponseBase {
    /**
     * Type of the response, narrowed to either the full response or the header.
     */
    readonly type: HttpEventType.Response | HttpEventType.ResponseHeader;
}

However, HttpResponseBase contains the type property, which is not allowed.

Try this:

const a = createAction('a', props<{ error: HttpErrorResponse }>());

Thanks @markostanimirovic 馃憤

I wonder if we could make it clearer in the docs, e.g. don't do this (code example) and do with a prop name instead (code example).

Fyi, I'm going to steal this and going to create a lint rule for this add eslint-plugin-ngrx.

@dev054 do you think it would be more clear if we would change the error message?
If so, do you have a proposition?

Does this succinctly describe the problem?

interface with "type" property not allowed because it conflicts with the action's type

The docsite could also note the list of illegal generic arguments for props/ the type of the creator function argument.

Was this page helpful?
0 / 5 - 0 ratings