Skip to content

Conversation

@Andarist
Copy link
Collaborator

@Andarist Andarist commented Apr 16, 2022

fixes #3217

TS minimal repro
Minimal repro fixed with Compute

The problem is in the fact that we are using an intersection here and TS doesn't the contextual type for a function in such a situation. I'm working a on a fix for this in the TypeScript itself, here, but until that lands... we must avoid an intersection here and by using Compute we make the type at this position to be computed earlier and thus TS can treat it an object type when needed.

EDIT:// actually... Compute-based solution caused our CI to got out of memory, so I've simplified the fix and just "merged" the intersection manually, into a single mapped type

@Andarist Andarist requested a review from davidkpiano April 16, 2022 08:40
@changeset-bot
Copy link

changeset-bot bot commented Apr 16, 2022

🦋 Changeset detected

Latest commit: 85c8e6f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghost
Copy link

ghost commented Apr 16, 2022

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 16, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 85c8e6f:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

on: {
EVENT_WITH_FLAG: {
actions: (_context, event) => {
((_accept: 'EVENT_WITH_FLAG') => {})(event.type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty clever!

@Andarist Andarist merged commit fe5f0e6 into main Apr 16, 2022
@Andarist Andarist deleted the andarist/fix-inline-action-inference branch April 16, 2022 12:46
@github-actions github-actions bot mentioned this pull request Apr 16, 2022
nevilm-lt pushed a commit to nevilm-lt/xstate that referenced this pull request Apr 22, 2022
…nsition actions not having their argument types inferred (statelyai#3228)

* Added a failing test for inference with inline actions

* Fixed an issue with inline functions in the config object used as transition actions not having their argument types inferred

* Fix small type errors

* Try a solution based on merging the mapped type

Co-authored-by: Matt Pocock <mattpocockvoice@gmail.com>
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

Successfully merging this pull request may close these issues.

4 participants