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

Broken type of on function when created outside of createReducer factory function #3576

Closed
1 of 2 tasks
alex-okrushko opened this issue Sep 16, 2022 · 0 comments · Fixed by #3577
Closed
1 of 2 tasks
Assignees

Comments

@alex-okrushko
Copy link
Member

Which @ngrx/* package(s) are the source of the bug?

store

Minimal reproduction of the bug/regression with instructions

(Discovered as a result of the attempted NgRx merge into g3)

Since #2982 when on function was created outside of the createReducer, the State type is being incorrectly inferred as unknown.

E.g. the following code:

    interface State { name: string };
    const foo = createAction('FOO', props<{ foo: string }>());
    const onFn = on(foo, (state: State, action) => ({  name: action.foo }));

would produce the following error:

Argument of type '(state: State, action: { foo: string; } & TypedAction<"FOO"> & { type: "FOO"; }) => { name: string; }' 
is not assignable to parameter of type 'OnReducer<unknown, [ActionCreator<"FOO", (props: { foo: string; }) => { foo: string; } & TypedAction<"FOO">>]>'.
  Types of parameters 'state' and 'state' are incompatible.
    Type 'unknown' is not assignable to type 'State'

Minimal reproduction of the bug/regression with instructions

on function should correctly infer the State type that's specified explicitly in the OnReducer function.

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

NgRx: latest 14.3.1

Other information

No response

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

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

Successfully merging a pull request may close this issue.

1 participant