Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Invoke configuration does not support string type when given array #3744

Closed
viglucci opened this issue Jan 4, 2023 · 1 comment
Closed
Labels

Comments

@viglucci
Copy link
Contributor

viglucci commented Jan 4, 2023

Description

There are type errors when attempting to use a string as the name of a state in the onDone or onError portion for an invoked service, even though this should be considered a perfectly valid configuration, and without typescript functions just fine.

Expected result

The following simple machine should not cause type errors:

import { createMachine } from "xstate";

createMachine({
    invoke: {
        src: () => () => { },
        onDone: [{ target: "a" }, "b"],
    },
    states: {
        a: {},
        b: {},
    },
});

Actual result

Typescript is unhappy:

Type '{ src: () => () => void; onDone: (string | { target: string; })[]; }' is not assignable to type 'SingleOrArray<AnyStateMachine | InvokeConfig<unknown, AnyEventObject>>'.
  Types of property 'onDone' are incompatible.
    Type '(string | { target: string; })[]' is not assignable to type 'string | SingleOrArray<TransitionConfig<unknown, DoneInvokeEvent<any>>>'.
      Type '(string | { target: string; })[]' is not assignable to type 'TransitionConfig<unknown, DoneInvokeEvent<any>>[]'.
        Type 'string | { target: string; }' is not assignable to type 'TransitionConfig<unknown, DoneInvokeEvent<any>>'.
          Type 'string' has no properties in common with type 'TransitionConfig<unknown, DoneInvokeEvent<any>>'.ts(2322)

Reproduction

https://codesandbox.io/s/currying-shadow-8tnshi?file=/src/index.ts

Additional context

Originally reported here: statelyai/xstate-tools#275

@Andarist
Copy link
Member

This was fixed by #3745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants