typesafe-actions icon indicating copy to clipboard operation
typesafe-actions copied to clipboard

AsyncActionCreatorBuilder doesn't support generics

Open voliva opened this issue 5 years ago • 0 comments

Description

Even though AsyncActionCreatorBuilder can be easily used by providing set and fixed types, it can't be used when trying to retrieve generics.

Mandatory info

  • [x] Did you checked compatibility notes and migration guides?

How to Reproduce


function asyncActionEnhancer<
    TRequestType,
    TRequestValue,
    TResponseType,
    TResponseValue,
    TError
>(
    asyncAction: AsyncActionCreatorBuilder<
        [TRequestType, TRequestValue],
        [TResponseType, TResponseValue],
        [TError, Error]
    >
): TRequestValue {
    /** Logic here */
}

Current behaviour

TS shows an error on the line [TRequestType, TRequestValue]:

Type 'TRequestValue' is not assignable to type '[TRequestType, TRequestValue] extends [TRequestType, [any, any]] ? ([any, any] & TRequestValue)[0] : TRequestValue'.

Expected behaviour

TS should be able to infer the function generics from asyncAction

Suggested solution(s)

It already worked previously in v4 with the type AsyncActionCreator from src/create-async-action, which was typed with much less type constraints than the currentAsyncActionCreatorBuilder

Project Dependencies

  • Typesafe-Actions Version: 5.1.0
  • TypeScript Version: 3.7.2
  • tsconfig.json:
    "composite": true,
    "noEmit": true,
    "declaration": true,
    "strict": true,
    "jsx": "react",
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "removeComments": true,
    "isolatedModules": true,
    "types": ["react", "jest"]

voliva avatar Jan 22 '20 15:01 voliva