statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.21k stars 1.26k forks source link

Bug: `input` is not inferred using `fromPromise` in `setup` #5102

Closed FedericoBiccheddu closed 1 month ago

FedericoBiccheddu commented 1 month ago

XState version

XState version 5

Description

Using fromPromise for defining actors in setup, the parameter input is not inferred.

Expected result

I expect the input to be inferred as the useActor works correctly and requires input to be provided.

Actual result

Property 'myInput' does not exist on type '{}'. ts(2339)

Reproduction

https://codesandbox.io/p/devbox/xstate-ts-actor-input-frompromise-infer-zwfvs5?file=%2Fsrc%2FfeedbackMachine.ts%3A26%2C63-26%2C76

Additional context

xstate: 5.18.2 @xstate/svelte: 3.0.5

Andarist commented 1 month ago

It works OK as intended, the input that you configure for your promise actor is its input - not the input given to the outer machine. Please take a look at this TS playground that, I hope, will help to clarify the confusion: TS playground

FedericoBiccheddu commented 1 month ago

I found it a bit counterintuitive, but I understand it now; thank you for the example.

So the suggested approach is to provide the second generic to fromPromise in order to keep the parameter (promiseCreator) correctly typed, right? For context, I use signal and sometimes emit, so I need them typed.

Andarist commented 1 month ago

Providing explicit generic to fromPromise is probably the easiest.

FedericoBiccheddu commented 1 month ago

Thank you, I think we can close then as there is a good enough solution.