diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 733f92574e..007770e329 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -765,17 +765,82 @@ export type InvokeConfig< TMeta extends MetaObject > = IsLiteralString extends true - ? DistributeActors< - TContext, - TEvent, - TActor, - TAction, - TGuard, - TDelay, - TEmitted, - TMeta, - TActor - > + ? + | DistributeActors< + TContext, + TEvent, + TActor, + TAction, + TGuard, + TDelay, + TEmitted, + TMeta, + TActor + > + | { + id?: never; + + systemId?: string; + src: AnyActorLogic; + + input?: + | Mapper + | NonReducibleUnknown; + /** + * The transition to take upon the invoked child machine reaching + * its final top-level state. + */ + onDone?: + | string + | SingleOrArray< + TransitionConfigOrTarget< + TContext, + DoneActorEvent, // TODO: consider replacing with `unknown` + TEvent, + TActor, + TAction, + TGuard, + TDelay, + TEmitted, + TMeta + > + >; + /** + * The transition to take upon the invoked child machine sending an + * error event. + */ + onError?: + | string + | SingleOrArray< + TransitionConfigOrTarget< + TContext, + ErrorActorEvent, + TEvent, + TActor, + TAction, + TGuard, + TDelay, + TEmitted, + TMeta + > + >; + + onSnapshot?: + | string + | SingleOrArray< + TransitionConfigOrTarget< + TContext, + SnapshotEvent, + TEvent, + TActor, + TAction, + TGuard, + TDelay, + TEmitted, + TMeta + > + >; + } : { /** * The unique identifier for the invoked machine. If not specified, this diff --git a/packages/core/test/setup.types.test.ts b/packages/core/test/setup.types.test.ts index 6f769c6a11..990a73af8e 100644 --- a/packages/core/test/setup.types.test.ts +++ b/packages/core/test/setup.types.test.ts @@ -9,6 +9,7 @@ import { emit, enqueueActions, EventFrom, + fromCallback, fromPromise, fromTransition, log, @@ -492,8 +493,11 @@ describe('setup()', () => { }); }); - it('should not accept an `assign` with a spawner that tries to spawn an unknown actor when actors are not configured', () => { + it('should not accept an `assign` with a spawner that tries to spawn an unknown actor when actors are configured', () => { setup({ + actors: { + foo: fromPromise(async () => {}) + }, actions: { spawnFetcher: assign(({ spawn }) => { return { @@ -506,10 +510,10 @@ describe('setup()', () => { }); }); - it('should not accept an invoke that tries to invoke an unknown actor when actors are not configured', () => { + it('should accept an invoke that tries to invoke an unknown actor when actors are not configured', () => { setup({}).createMachine({ + // @ts-expect-error invoke: { - // @ts-expect-error src: 'unknown' } }); @@ -2397,4 +2401,17 @@ describe('setup()', () => { ((_accept: ContextFrom) => {})({ myVar: 'whatever' }); }); + + it('should accept an invoke that tries to invoke an inline actor when actors are not configured', () => { + setup({}).createMachine({ + states: { + //... + exampleState: { + invoke: { + src: fromCallback(() => {}) + } + } + } + }); + }); });