dphilipson / typescript-fsa-reducers

Fluent syntax for defining typesafe reducers on top of typescript-fsa.
MIT License
220 stars 16 forks source link

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

Open nbgraham opened 3 years ago

nbgraham commented 3 years ago

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

dphilipson commented 3 years ago

Thanks for the report. I'll take a look at this.