piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

Argument type (payload: string) => PayloadAction<"NAME", type> is not assignable to parameter type ((...args: any[]) => Exclude<Action, THandledAction>)[] | ((...args: any[]) => Exclude<Action, THandledAction>) #179

Closed hsz closed 4 years ago

hsz commented 4 years ago

Description

I have noticed that after upgrading library to 5.0.0-3, PhpStorm complains when I add more than one handleAction to my reducer. IDE shows following inspection warning:

Argument type (payload: string) => PayloadAction<"SET_TEXT2", string> is not assignable to parameter type ((...args: any[]) => Exclude<Action, THandledAction>)[] | ((...args: any[]) => Exclude<Action, THandledAction>)

I am not sure, if typesafe-actions can be improved to avoid such warning or there is nothing that can be done and issue is caused because of their glitch. However, I'd like to verify that with you at first.

Steps to Reproduce

  1. Create a simple reducer with createReducer(initialState).
  2. Add two or more hanlders.
  3. Action in second handler is underlined with above warning.

CodeSandbox to help you reproduce issue in isolation https://github.com/hsz/typesafe-actions-issue

Exact file with the issue: https://github.com/hsz/typesafe-actions-issue/blob/master/src/reducers/content.ts

Expected behavior

PhpStorm should not show any warning.

Project Dependencies

Environment (optional)

piotrwitek commented 4 years ago

Hey @hsz, What is the result of tsc, is it showing you an error? IDE related issues should not be a concern of this library.

hsz commented 4 years ago

As mentioned - this is just the IDE warning. tsc does not complain about it. I'm just wondering if current types aren't too complex/hacky?

piotrwitek commented 4 years ago

IDE warning is using TS language services, maybe it's a bug in IDE or language services API. I would recommend searching in TS Github repo as I'm not aware of such issues and if tsc compiler doesn't show an error than it's not directly related to the library code.

hsz commented 4 years ago

Sure, I'll report it to JetBrains then.

piotrwitek commented 4 years ago

@hsz you can also try to check in vscode and see if the same error happen in vscode, then you'll know if the issue is in PHPStorm or in language services.