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

Action creators are not 100% type safe #27

Open
@mixvar

Description

@mixvar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions