xstate: Version 4.23.0 breaks typing of "$" prefixed service inside svelte component

Given this

const machine = model.createMachine(...)
const service = interpret(machine).start();

Until 4.22

const { someData } = $service.context // This returns the correct type

From 4.23.0

service.subscribe((state) => {
  state.context // This still returns a correct type
})
const { someData } = $service.context // $service becomes any

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 22 (17 by maintainers)

Most upvoted comments

I think the tag @xstate/svelte is inaccurate here, this issue is caused by the typing change in the core and there is nothing to do with @xstate/svelte.

But I’d say severity of this issue has dropped significantly by the introduction of useSelector to @xstate/svelte. I’m pretty positive that one should always prefer using useSelector instead of direct access with $.