xstate icon indicating copy to clipboard operation
xstate copied to clipboard

Bug: Schema of context defined, yet not recognized in action

Open saikatdas0790 opened this issue 3 years ago • 2 comments

Description

Trying to follow along from an example here

The schema is defined in the context but it's not detected in TypeScript and the context property is shown as undefined image

Here is a minimal reproduction: https://codesandbox.io/s/currying-wind-4ohyf8?file=/src/index.ts

Expected result

No type errors

Actual result

Getting type errors

Reproduction

https://codesandbox.io/s/currying-wind-4ohyf8?file=/src/index.ts

Additional context

XState version: 4.32.0

saikatdas0790 avatar May 12 '22 06:05 saikatdas0790

I think the problem here might be related to a certain circularity in the assign's type definition that makes it hard for TS to infer this.

As a workaround you can type context parameter explicitly, like here. It's not ideal but fixing this in XState might take some time.

Andarist avatar May 12 '22 11:05 Andarist

But wouldn't this also disable the typegen tooling completely? That's more harm done, no?

saikatdas0790 avatar May 12 '22 16:05 saikatdas0790

Closing as the sandbox could not be found and may no longer be reproducible with the latest XState version.

If you can share a reproducible sandbox with the latest XState version, will reopen.

davidkpiano avatar Jan 28 '23 23:01 davidkpiano