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: 'spawn(machine)' does not validate missing actions like 'useMachine(machine)' does #3725

Closed
kirill578 opened this issue Dec 23, 2022 · 2 comments

Comments

@kirill578
Copy link

Description

it appears that machines that are spawned lack the validation we get with useMachine. Looks like the spawn action is accepting machines that have a non 'never' values under tsConfig.missingImplementations

Screen Shot 2022-12-23 at 10 51 36 AM

Expected result

it should throw a typescript error when invoking a non fully implemented machine

Actual result

it does not error

Reproduction

https://codesandbox.io/s/elastic-visvesvaraya-lgbnlj?file=/src/index.ts

Additional context

No response

@kirill578 kirill578 added the bug label Dec 23, 2022
@kirill578
Copy link
Author

I ended up adding this no-op wrapper workaround to my machines to ensure they are fully defined:

import {
  AnyStateMachine,
  AreAllImplementationsAssumedToBeProvided,
} from "xstate";

// workaround for this bug https://github.com/statelyai/xstate/issues/3725
export function confirmAllImplementationsAreProvided<
  TMachine extends AnyStateMachine
>(
  m: AreAllImplementationsAssumedToBeProvided<
    TMachine["__TResolvedTypesMeta"]
  > extends true
    ? TMachine
    : never
): TMachine {
  return m;
}
spawn(AreAllImplementationsAssumedToBeProvided(myMachine))

@Andarist
Copy link
Member

Duplicate of #3405

@Andarist Andarist marked this as a duplicate of #3405 Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants