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

createStandardAction / createAsyncAction with optional payload not working after upgrade from v3 to v4 #178

Closed unekinn closed 5 years ago

unekinn commented 5 years ago

Description

As described in the migration guide, I've replaced void with undefined in calls to createStandardAction and createAsyncAction.

However, this breaks a few actions where the payload type was SomeType | void. This would previously create an action that could be called both with and without a payload. Now, I have to explicitly send undefined as the payload.

Interestingly, if I revert the change of void to undefined throughout my codebase's calls to create*Action, everything seems to work as expected. Is the move to undefined actually necessary?

Steps to Reproduce

import { createStandardAction } from 'typesafe-actions'
const payloadOrUndefined = createStandardAction('ACTION1')<
  number | undefined
>();
// Fails to typecheck:
// Expected 1 arguments, but got 0
// type-helpers.d.ts(69, 72): An argument for 'payload' was not provided.
payloadOrUndefined();

CodeSandbox to help you reproduce issue in isolation https://codesandbox.io/s/typesafe-actions-reference-project-85nbn

Expected behavior

payloadOrUndefined() defined above should return an action with type

{ type: 'ACTION1', payload: number | undefined }

instead of failing to typecheck

Suggested solution(s)

Project Dependencies

piotrwitek commented 5 years ago

Hey @larskinn I confirm it is working in the most recent version so I might update the migration guide on this point.

piotrwitek commented 5 years ago

Closed by 8f6b2a40a04f4c99baf49dd3120271d439a3a0b0