Xstate: Typestates not working as expected with xstate

Created on 25 Nov 2019  路  5Comments  路  Source: davidkpiano/xstate

Description

not able to narrow typestate types when subscribing to a state machine service

Expected Result

within a state.maches("foo") { ... } condition, types to be narrowed to the appropriate State type

Actual Result

types are not narrowed, you get the Context type

xstate-issue

Reproduction

https://codesandbox.io/s/awesome-tree-qom29 (see src/index.ts L62)

Additional context

bug typescript

Most helpful comment

Fix being released soon-ish: #868

All 5 comments

Fix for this coming 馃敎 but for now, this should be general a workaround:

if (state.matches<any>('something')) {
  // ...
}

https://github.com/RafalFilipek/xstate-typestates-bug I've just updated my example. Still no luck. I think I'll wait for fix. I can live with that since we have optional chaining and nullish coalescing :)

Having same issue with useMachine from @xstate/react

Fix being released soon-ish: #868

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnordt picture hnordt  路  3Comments

mattiamanzati picture mattiamanzati  路  3Comments

laurentpierson picture laurentpierson  路  3Comments

amelon picture amelon  路  3Comments

3plusalpha picture 3plusalpha  路  3Comments