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: A context property on a machine blows away actor input type checking #5209

Open
SlexAxton opened this issue Feb 19, 2025 · 3 comments
Open
Labels

Comments

@SlexAxton
Copy link

XState version

XState version 5

Description

My actor inputs are typechecked until I add a context function to my machine, and then they're no longer typechecked. ts playground has reproduction

Expected result

I think the ts-expect-error should be correct regardless of if the context function is being set.

Image

Actual result

Image

Reproduction

https://www.typescriptlang.org/play/?ts=5.6.3#code/JYWwDg9gTgLgBAbzgZwKYwK5gDRwGZQQgAKhIwacAvvmXAEQAeyMAhjKvQNxwD0vcGAE8wqZAC44AVgB0ARgAcMgEwAoVcNFwAwhAB2HRvAC8iOBAwcokllGB6A5tS7qAxvpZwQrVwAt7qHCmaJhgABQIqnCCImKSCDSsyIhR0XDuBqhGkrqZRi5pcPZgljn6hjAF1NipPjDQEimFACYQAMqYeHiSBESkRBSoYamFSUJ6rnARRXol8FTxM3OL9nqo1nB6GCAARuvU1ACUQQB8TYVpUOgYUHpwALLsvjJQrHqtIGHHANRLljKrdZVQpUEZwQ41aJUGpUQ4yVxXdioR5+AIRVL8OAASTwcCEFnSRBAqAM5ksgn8yQANgFcDBfIFNIE-KhXABrexOfQUwJ1aBwADu0DZyVYDlY9lSGQqkmmxXJsNOfxgkJmADcIGzUPEwcgoK5JPRWh0MF16KrovKYDqLnwBAABGDIAC0WVErhgrqghCgYOirTEBgAoowKNaGHgIBBzX6ZmsNlIwdDUsnYS4gA

Additional context

No response

@SlexAxton SlexAxton added the bug label Feb 19, 2025
@with-heart
Copy link
Contributor

with-heart commented Feb 20, 2025

Maybe another interesting version of types getting wonked in this case: it also stops checking the context types:

Yeah it's really weird that the presence of a nested type error disables the expected "missing context" type error for the entire config object, even if you use @ts-expect-error or @ts-ignore to disable the nested type error.

Something else I noticed while playing around with your examples is that the type of invoke is either inferred or an assigned type depending on whether context is present or not:

  • with context (inferred):

    {
      readonly src: "doStuff"
      readonly input: {
        readonly inner: number
      }
    }
  • without context (assigned type):

    (property) invoke?: SingleOrArray<{
        systemId?: string | undefined;
        src: "doStuff";
        id?: string | undefined;
        input: {
            inner: number;
        } | Mapper<{
            outer: string;
        }, AnyEventObject, {
            inner: number;
        }, AnyEventObject> | undefined;
        onDone?: SingleOrArray<...>;
        onError?: SingleOrArray<...>;
        onSnapshot?: SingleOrArray<...>;
    } | {
      ...;
    }> | undefined

ts playground example of the above.

And if we modify your first example a tiny bit, we can see that the above holds true. When context is commented out and the type error is thrown on invoke.input.doesntExist, invoke has an assigned type, but if we uncomment context then invoke becomes inferred and the type error on invoke.input.doesntExist disappears: ts playground

This switch between inferred and assigned type seems to be the difference in whether an error is thrown on invoke.input or not.

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