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 98 forks source link

createAsyncAction incorrect ReturnType for an array with 2 elements whose types are known #215

Closed egonm12 closed 4 years ago

egonm12 commented 4 years ago

Description

The return type of my async actions are not as expected. When I want my payload shape to be [string, string] it somehow returns payload: string; meta: string. This is not the case when I would do [string, string, string]. In that case payload is of type [string, string, string].

How to Reproduce

import { createAsyncAction } from "typesafe-actions";

const myAsyncActions = createAsyncAction(
  "FETCH_BEGIN",
  "FETCH_SUCCESS",
  "FETCH_FAILURE",
)<[string, string], undefined, undefined>()

type MyType = ReturnType<typeof myAsyncActions.request>;

Expected behavior

MyType = {
  type: "FETCH_BEGIN";
  payload: [string, string]
}

Actual behavior

MyType = {
  type: "FETCH_BEGIN";
  payload: string;
  meta: string;
}

Suggested solution(s)

Not looked into possible solutions yet

Project Dependencies

piotrwitek commented 4 years ago

It's by design to allow a way to define both payload and meta. If you want to use a tuple as type argument please use payload + meta syntax:

const myAsyncActions = createAsyncAction(
  'FETCH_BEGIN',
  'FETCH_SUCCESS',
  'FETCH_FAILURE'
)<[[string, string], undefined], undefined, undefined>();