aikoven / typescript-fsa

Type-safe action creator utilities
MIT License
607 stars 28 forks source link

TypeScript 3.6 Compatibility issue #77

Closed septs closed 5 years ago

septs commented 5 years ago

Example code

fsa-issue.zip

$ unzip fsa-issue.zip
$ cd fsa-issue
$ npm install
$ npm test

> fsa-issue@ test /Users/septs/Projects/fsa-issue
> tsc --noEmit

issue.ts:8:6 - error TS2345: Argument of type '{ (payload: Success<unknown, void>, meta?: { [key: string]: any; } | null | undefined): Action<Success<unknown, void>>; type: string; match: (action: AnyAction) => action is Action<Success<unknown, void>>; }' is not assignable to parameter of type 'ActionCreator<void>'.
  Type '{ (payload: Success<unknown, void>, meta?: { [key: string]: any; } | null | undefined): Action<Success<unknown, void>>; type: string; match: (action: AnyAction) => action is Action<Success<unknown, void>>; }' is not assignable to type '{ (payload: void, meta?: { [key: string]: any; } | null | undefined): Action<void>; type: string; match: (action: AnyAction) => action is Action<void>; }'.
    Types of property 'match' are incompatible.
      Type '(action: AnyAction) => action is Action<Success<unknown, void>>' is not assignable to type '(action: AnyAction) => action is Action<void>'.
        Type predicate 'action is Action<Success<unknown, void>>' is not assignable to 'action is Action<void>'.
          Type 'Action<Success<unknown, void>>' is not assignable to type 'Action<void>'.
            Type 'Success<unknown, void>' is not assignable to type 'void'.
              Type '{ params: unknown; } & { result: void; }' is not assignable to type 'void'.

8 test(async.done)

npm ERR! Test failed.  See above for more details.

Why void with Result?

typescript-fsa-redux-thunk in NO RETURN async procedure

const doThing = createAsyncAction("DO_THING", async () => { return; });

// doThing.async.done
// The result of the reasoning type is:
//      Action<Success<unknown, void>>

see xdave/typescript-fsa-redux-thunk#17 see xdave/typescript-fsa-redux-thunk#14

aikoven commented 5 years ago

Payloads of async action creators always carry params with them. So if the result of async job is void, the payload of the done action would look like {params: ...}.

The code you sent compiles fine if you change the definition of test to

declare function test(creator: ActionCreator<Success<unknown, void>>): void;
septs commented 5 years ago

https://github.com/xdave/typescript-fsa-redux-thunk/issues/17#issuecomment-531446038