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

i can't get the origin action type in reducer #57

Closed vegawong closed 6 years ago

vegawong commented 6 years ago

code like that: image my action type like that: image it can't get the origin action type via switch & case is there any wrong in my code?

piotrwitek commented 6 years ago

Hi, Please show how you create fetchDataSuccess function

vegawong commented 6 years ago
export const fetchDataSuccess = createStandardAction(types.FETCH_DATA_SUCCESS)<
    PlainObject
>()
vegawong commented 6 years ago

I think it's typescript's problem; it can only show the property all the union type has; some action has not payload . so it would show the error. when i change my actions all create as PayloadAction and it work!

piotrwitek commented 6 years ago

I understand, please could you also show contents of entire './actions' module, I could tell you which action could be problematic

vegawong commented 6 years ago

image this is action & reducer file

piotrwitek commented 6 years ago

@vegawong I think you shouldn't be using never type, it should be void, can you try it? If you take a look at docs it is always using void.

vegawong commented 6 years ago

nothing worked! it also create as EmptyAction type that only as type property. it can't work in union type.

vegawong commented 6 years ago

but i saw that it work in the sample source, i try to find out that maybe some wrong in my tsconfig

vegawong commented 6 years ago

hello! I had found out what's wrong with that? but.... emmmm... I has no idea to deal with. if i did not use constant type from another module,and then actionCreator would get the collect type and it work! like that: image

but, when is use the constant from another module, actionCreator can't get the collect type like that:

image

vegawong commented 6 years ago

@piotrwitek oh my god! It is my fault; my constant code like that:

const PAGENAME = 'dzcf/Prescriptions'

export const FETCH_DATA = `${PAGENAME}/fetchData`

export const FETCH_DATA_SUCCESS = `${PAGENAME}/fetchDataSuccess`

I type the code use String Template and typescript is not suport this way for String Literals, so that it can't get the right value as type for getType function. thanks