piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

AsyncActionCreatorBuilder doesn't support generics #220

Open voliva opened 4 years ago

voliva commented 4 years ago

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

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