Skip to content

Commit 659efd5

Browse files
authored
Fixed types compatibility with TS 5.0 (#4728)
1 parent 2f1d36a commit 659efd5

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

.changeset/honest-moons-ring.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'xstate': patch
3+
---
4+
5+
Fixed compatibility issue of the internal type definitions with TypeScript 5.0

packages/core/src/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type ToProvidedActor<
6161
id: IsNever<TChildrenMap> extends true
6262
? string | undefined
6363
: K extends keyof Invert<TChildrenMap>
64-
? Invert<TChildrenMap>[K]
64+
? Invert<TChildrenMap>[K] & string
6565
: string | undefined;
6666
};
6767
}>;

packages/core/src/types.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -2348,19 +2348,21 @@ export type ToChildren<TActor extends ProvidedActor> =
23482348
// or maybe even `TActor["logic"]` since it's possible to configure `{ src: string; logic: SomeConcreteLogic }`
23492349
// TODO: consider adding `| undefined` here
23502350
Record<string, AnyActorRef>
2351-
: ToConcreteChildren<TActor> &
2352-
{
2353-
include: {
2354-
[id: string]: TActor extends any
2355-
? ActorRefFrom<TActor['logic']> | undefined
2356-
: never;
2357-
};
2358-
exclude: {};
2359-
}[undefined extends TActor['id'] // if not all actors have literal string IDs then we need to create an index signature containing all possible actor types
2360-
? 'include'
2361-
: string extends TActor['id']
2351+
: Compute<
2352+
ToConcreteChildren<TActor> &
2353+
{
2354+
include: {
2355+
[id: string]: TActor extends any
2356+
? ActorRefFrom<TActor['logic']> | undefined
2357+
: never;
2358+
};
2359+
exclude: {};
2360+
}[undefined extends TActor['id'] // if not all actors have literal string IDs then we need to create an index signature containing all possible actor types
23622361
? 'include'
2363-
: 'exclude'];
2362+
: string extends TActor['id']
2363+
? 'include'
2364+
: 'exclude']
2365+
>;
23642366

23652367
export type StateSchema = {
23662368
states?: Record<string, StateSchema>;

0 commit comments

Comments
 (0)