Skip to content

Commit

Permalink
Fixed ToProvidedActor helper type (#4499)
Browse files Browse the repository at this point in the history
* Add failing test

* Fixed `ToProvidedActor` helper

* simplify test to avoid a runtime error

* add changeset

---------

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
davidkpiano and Andarist authored Nov 27, 2023
1 parent ba4e8b3 commit c9908b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix-toprovidedactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed the `TActor` type passed down by `setup` in absence of provided actors.
10 changes: 7 additions & 3 deletions packages/core/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ type DefaultToAnyActors<TActors extends Record<string, AnyActorLogic>> =
// this could be reconsidered in the future
type ToProvidedActor<
TChildrenMap extends Record<string, string>,
TActors extends Record<Values<TChildrenMap>, AnyActorLogic>
TActors extends Record<Values<TChildrenMap>, AnyActorLogic>,
TResolvedActors extends Record<
string,
AnyActorLogic
> = DefaultToAnyActors<TActors>
> = Values<{
[K in keyof DefaultToAnyActors<TActors> & string]: {
[K in keyof TResolvedActors & string]: {
src: K;
logic: TActors[K];
logic: TResolvedActors[K];
id: IsNever<TChildrenMap> extends true
? string | undefined
: K extends keyof Invert<TChildrenMap>
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/setup.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,4 +923,14 @@ describe('setup()', () => {
| ActorRefFrom<typeof child2>
| undefined;
});

it('should accept `assign` when no actor and children types are provided', () => {
setup({}).createMachine({
on: {
RESTART: {
actions: assign({})
}
}
});
});
});

0 comments on commit c9908b7

Please sign in to comment.