Skip to content

feat(core): add actions, guards, delays to SetupTypes interface#5446

Open
cevr wants to merge 1 commit intostatelyai:mainfrom
cevr:feat/setup-action-types
Open

feat(core): add actions, guards, delays to SetupTypes interface#5446
cevr wants to merge 1 commit intostatelyai:mainfrom
cevr:feat/setup-action-types

Conversation

@cevr
Copy link
Contributor

@cevr cevr commented Jan 13, 2026

Summary

  • Adds type slots for actions, guards, and delays to the SetupTypes interface
  • Enables explicit type annotations for machines, helping break TypeScript inference chains
  • Addresses performance issues and "excessively large and possibly infinite" type errors in large codebases

Problem

In large codebases that share types between backend and frontend, TypeScript's inference on actions/guards/delays can cause:

  • Significant slowdowns in type checking
  • "Excessively large and possibly infinite" TypeScript errors
  • Inability to explicitly type machines like const machine: StateMachine<...> = setup({...}).createMachine({})

Solution

Add actions, guards, and delays to SetupTypes (like the existing context, events, etc.). This allows users to declare types explicitly rather than relying solely on inference.

// Before: Types always inferred from implementations, causing deep inference chains
const { createMachine } = setup({
  actions: {
    increment: assign(({ context }) => ({ count: context.count + 1 })),
  }
});

// After: SetupTypes includes action/guard/delay slots for explicit annotation support
type MySetupTypes = {
  context: { count: number };
  events: { type: 'INC' };
  actions: { type: 'increment'; params: undefined };
  guards: { type: 'isValid'; params: undefined };
  delays: 'timeout';
};

Changes

  • types.ts: Add TAction, TGuard, TDelay type parameters and properties to SetupTypes
  • setup.ts: Pass action/guard/delay types to SetupTypes in the types parameter
  • setup.types.test.ts: Add tests for new type slots

Test plan

  • TypeScript typecheck passes
  • All 159 setup type tests pass
  • All 1687 tests in the core package pass

🤖 Generated with Claude Code

Add type slots for actions, guards, and delays to the SetupTypes interface.
This enables explicit type annotations for machines, which helps break
TypeScript inference chains in large codebases that can cause performance
issues and "excessively large and possibly infinite" type errors.

Changes:
- Add TAction, TGuard, TDelay type parameters to SetupTypes interface
- Add actions, guards, delays properties to SetupTypes
- Update MachineTypes to extend SetupTypes with new parameters
- Update setup() to pass action/guard/delay types to SetupTypes
- Add type tests for new functionality

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2026

⚠️ No Changeset found

Latest commit: 4cc341d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@davidkpiano
Copy link
Member

cc. @Andarist to take a quick look to see if this is needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants