Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Action creators are not 100% type safe #27

Open
mixvar opened this issue May 20, 2019 · 0 comments · May be fixed by #29
Open

Action creators are not 100% type safe #27

mixvar opened this issue May 20, 2019 · 0 comments · May be fixed by #29

Comments

@mixvar
Copy link

mixvar commented May 20, 2019

action creators allow for omitting payload which can easily lead to runtime errors :(

from the example:

const add = createAction<number>('add'); // payload of type number

add(10) // OK
add() // should not compile
add(undefined) // should not compile

handleAction(add, (state, { payload }) => { // payload infered as number (not number | undefined)
    state.counter += payload; // state.counter will be NaN 💀
}),

Tested with typescript 3.4.5 and all strict rules enabled.

mixvar pushed a commit to mixvar/redux-ts-utils that referenced this issue May 21, 2019
- enforce correct number of arguments using fuction overloads
- update README

closes knpwrs#27 and knpwrs#28
@mixvar mixvar linked a pull request May 21, 2019 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant