Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 76 additions & 11 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,82 @@ export type InvokeConfig<
TMeta extends MetaObject
> =
IsLiteralString<TActor['src']> 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<TContext, TEvent, NonReducibleUnknown, TEvent>
| NonReducibleUnknown;
/**
* The transition to take upon the invoked child machine reaching
* its final top-level state.
*/
onDone?:
| string
| SingleOrArray<
TransitionConfigOrTarget<
TContext,
DoneActorEvent<any>, // 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
Expand Down
23 changes: 20 additions & 3 deletions packages/core/test/setup.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
emit,
enqueueActions,
EventFrom,
fromCallback,
fromPromise,
fromTransition,
log,
Expand Down Expand Up @@ -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 {
Expand All @@ -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'
}
});
Expand Down Expand Up @@ -2397,4 +2401,17 @@ describe('setup()', () => {

((_accept: ContextFrom<typeof machine>) => {})({ 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(() => {})
}
}
}
});
});
});
Loading