Skip to content

Type error for ActionCreator<boolean> with beta typescript-fsa #40

Open
@nbgraham

Description

@nbgraham

May be a moot point because it only happens with the beta

Reproduced:
https://codesandbox.io/s/modest-bird-8shhj

Argument of type '{ (payload: boolean, meta?: { [key: string]: any; } | null | undefined): Action<boolean>; type: string; match: (action: AnyAction) => action is Action<boolean>; }' is not assignable to parameter of type '{ (payload: false, meta?: { [key: string]: any; } | null | undefined): Action<false>; type: string; match: (action: AnyAction) => action is Action<false>; }'.
  Types of property 'match' are incompatible.
    Type '(action: AnyAction) => action is Action<boolean>' is not assignable to type '(action: AnyAction) => action is Action<false>'.
      Type predicate 'action is Action<boolean>' is not assignable to 'action is Action<false>'.
        Type 'Action<boolean>' is not assignable to type 'Action<false>'.
          Type 'boolean' is not assignable to type 'false'.ts(2345)

Seems to happen because of this part of the ActionCreator definition in the beta typescript-fsa

 & (Payload extends void ? {
    /**
     * Creates action with given payload and metadata.
     *
     * @param payload Action payload.
     * @param meta Action metadata. Merged with `commonMeta` of Action Creator.
     */
    (payload?: Payload, meta?: Meta): Action<Payload>;
} : {});

I reproduced in the Typescript playground and then fixed it by removing that clause

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions