Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
unekinn opened this issue Sep 13, 2019 · 2 comments

Comments

@unekinn
Copy link

unekinn commented Sep 13, 2019

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

  • Typesafe-Actions Version: 4.4.2
  • TypeScript Version: 3.6.3
  • tsconfig.json:
{
  "compilerOptions": {
    "strict": true
  }
}
@piotrwitek
Copy link
Owner

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

@piotrwitek
Copy link
Owner

Closed by 8f6b2a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants