Skip to content

Commit 51b8442

Browse files
authored
Fixed compatibility with the upcoming TS 5.4 (#4706)
* Remove redundant `Compute` * Fixed `StateValueMap` type * fixed type errors * add changeset
1 parent 0afa535 commit 51b8442

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

.changeset/lucky-mice-lick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'xstate': patch
3+
---
4+
5+
Fixed compatibility with the upcoming TypeScript 5.4

packages/core/src/stateUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ export function getStateNodes<
643643
}
644644
const subStateNodes = getStateNodes(
645645
subStateNode,
646-
stateValue[subStateKey]
646+
stateValue[subStateKey]!
647647
);
648648

649649
return allSubStateNodes.concat(subStateNodes);
@@ -684,7 +684,7 @@ export function transitionCompoundNode<
684684
const childStateNode = getStateNode(stateNode, subStateKeys[0]);
685685
const next = transitionNode(
686686
childStateNode,
687-
stateValue[subStateKeys[0]],
687+
stateValue[subStateKeys[0]]!,
688688
snapshot,
689689
event
690690
);

packages/core/src/types.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export type Actions<
295295
export type StateKey = string | AnyMachineSnapshot;
296296

297297
export interface StateValueMap {
298-
[key: string]: StateValue;
298+
[key: string]: StateValue | undefined;
299299
}
300300

301301
/**
@@ -2352,21 +2352,19 @@ export type ToChildren<TActor extends ProvidedActor> =
23522352
// or maybe even `TActor["logic"]` since it's possible to configure `{ src: string; logic: SomeConcreteLogic }`
23532353
// TODO: consider adding `| undefined` here
23542354
Record<string, AnyActorRef>
2355-
: Compute<
2356-
ToConcreteChildren<TActor> &
2357-
{
2358-
include: {
2359-
[id: string]: TActor extends any
2360-
? ActorRefFrom<TActor['logic']> | undefined
2361-
: never;
2362-
};
2363-
exclude: {};
2364-
}[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
2355+
: ToConcreteChildren<TActor> &
2356+
{
2357+
include: {
2358+
[id: string]: TActor extends any
2359+
? ActorRefFrom<TActor['logic']> | undefined
2360+
: never;
2361+
};
2362+
exclude: {};
2363+
}[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
2364+
? 'include'
2365+
: string extends TActor['id']
23652366
? 'include'
2366-
: string extends TActor['id']
2367-
? 'include'
2368-
: 'exclude']
2369-
>;
2367+
: 'exclude'];
23702368

23712369
export type StateSchema = {
23722370
states?: Record<string, StateSchema>;

packages/core/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function matchesState(
4747
return false;
4848
}
4949

50-
return matchesState(parentStateValue[key], childStateValue[key]);
50+
return matchesState(parentStateValue[key]!, childStateValue[key]!);
5151
});
5252
}
5353

0 commit comments

Comments
 (0)