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: Guard Logical Operator Functions Have Type Limitations #5067

Open
devanfarrell opened this issue Sep 7, 2024 · 0 comments
Open

Bug: Guard Logical Operator Functions Have Type Limitations #5067

devanfarrell opened this issue Sep 7, 2024 · 0 comments
Assignees

Comments

@devanfarrell
Copy link
Contributor

devanfarrell commented Sep 7, 2024

XState version

XState version 5

Description

A number of these type tests fail typescript validation

  it('should allow mixed guard patterns with logical guard operators', () => {
    setup({
      types: {} as {
        events: { type: 'TEST' };
      },
      guards: {
        paramGuard: (_, _arg: number) => true,
        plainGuard: () => true
      }
    }).createMachine({
      states: {
        plainAnd: {
          on: {
            TEST: {
              guard: and(['plainGuard', 'plainGuard'])
            }
          }
        },
        plainAndWithObjects: {
          on: {
            TEST: {
              guard: and([{ type: 'plainGuard' }, { type: 'plainGuard' }])
            }
          }
        },
        plainAndWithMixed: {
          on: {
            TEST: {
              guard: and(['plainGuard', { type: 'plainGuard' }])
            }
          }
        },
        // ! Failing
        parameterizedAnd: {
          on: {
            TEST: {
              guard: and([
                { type: 'paramGuard', params: () => 1 },
                { type: 'paramGuard', params: () => 1 }
              ])
            }
          }
        },
        // ! Failing
        plainAndParameterizedAnd: {
          on: {
            TEST: {
              guard: and([
                { type: 'plainGuard' },
                { type: 'paramGuard', params: () => 1 }
              ])
            }
          }
        },
        plainNot: {
          on: {
            TEST: {
              guard: not('plainGuard')
            }
          }
        },
        // ! Failing
        parameterizedNot: {
          on: {
            TEST: {
              guard: not({ type: 'paramGuard', params: () => 1 })
            }
          }
        },
        plainComposedAndNot: {
          on: {
            TEST: {
              guard: and([{ type: 'plainGuard' }, not('plainGuard')])
            }
          }
        },
        // ! Failing
        parameterizedComposedAndNot: {
          on: {
            TEST: {
              guard: and([
                { type: 'paramGuard', params: () => 1 },
                not({ type: 'paramGuard', params: () => 1 })
              ])
            }
          }
        }
      }
    });
  });

Expected result

This state machine to pass type validation based on the fact they seem to be supported in code.

Actual result

parameterizedAnd, plainAndParameterizedAnd, parameterizedNot, and parameterizedComposedAndNot do not pass typescript evaluation

Reproduction

https://codesandbox.io/p/sandbox/vigorous-minsky-rl75h2?file=%2Fmachine.ts%3A6%2C7

Additional context

I included a link but this is much easier to see when added to `/packages/core/

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