Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncActionCreatorBuilder doesn't support generics #220

Open
1 task done
voliva opened this issue Jan 22, 2020 · 0 comments
Open
1 task done

AsyncActionCreatorBuilder doesn't support generics #220

voliva opened this issue Jan 22, 2020 · 0 comments

Comments

@voliva
Copy link

voliva commented Jan 22, 2020

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

  • 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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant