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

Property 'payload' is missing in type 'AnyAction' #2

Open
huan opened this issue May 26, 2020 · 1 comment
Open

Property 'payload' is missing in type 'AnyAction' #2

huan opened this issue May 26, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@huan
Copy link
Owner

huan commented May 26, 2020

Minimum reproducible code snip:

import { Reducer, AnyAction } from 'redux'

type MyAction = {
  payload: number,
  type: 'TAP',
}

const f: Reducer<any, MyAction> = (s: any, ..._: any[]) => s
const r: Reducer<any, AnyAction> = f
// r is NOT ok.
void r

The error message of r is:

Type 'Reducer<any, MyAction>' is not assignable to type 'Reducer<any, AnyAction>'.
  Types of parameters 'action' and 'action' are incompatible.
    Type 'AnyAction' is not assignable to type 'MyAction'.ts(2322)

However,

const a1: MyAction = {
  payload: 42,
  type: 'TAP',
}
const a2: AnyAction = a1
// a2 is OK
void a2

To be fixed.

Related Issues

@huan huan added the bug Something isn't working label May 26, 2020
@huan huan changed the title Duck class is not compatible with DeepReadonly API Interface is not compatible with PayloadAction May 26, 2020
@huan huan changed the title API Interface is not compatible with PayloadAction Property 'payload' is missing in type 'AnyAction' May 30, 2020
@huan
Copy link
Owner Author

huan commented May 30, 2020

import { Reducer } from 'redux'

const count: Reducer<number> = (state: number) => {
  return state
}

void count

The above code will yield the following error message:

error TS2322: Type '(state: number) => number' is not assignable to type 'Reducer<number, AnyAction>'.
  Types of parameters 'state' and 'state' are incompatible.
    Type 'number | undefined' is not assignable to type 'number'.
      Type 'undefined' is not assignable to type 'number'.

3 const count: Reducer<number> = (state: number) => {

It turns out that we are declaring a function that can accept the state as the undefined | number type, however, the implemented function can only accept the number type of the argument, which can not satisfy the declaration.

huan added a commit that referenced this issue May 30, 2020
huan added a commit that referenced this issue May 30, 2020
huan added a commit to wechaty/ha that referenced this issue Jun 1, 2020
huan added a commit to wechaty/ha that referenced this issue Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant