diff --git a/.changeset/lucky-mice-lick.md b/.changeset/lucky-mice-lick.md new file mode 100644 index 0000000000..0d7fc1d790 --- /dev/null +++ b/.changeset/lucky-mice-lick.md @@ -0,0 +1,5 @@ +--- +'xstate': patch +--- + +Fixed compatibility with the upcoming TypeScript 5.4 diff --git a/packages/core/src/stateUtils.ts b/packages/core/src/stateUtils.ts index a97563d6f0..8704f66978 100644 --- a/packages/core/src/stateUtils.ts +++ b/packages/core/src/stateUtils.ts @@ -643,7 +643,7 @@ export function getStateNodes< } const subStateNodes = getStateNodes( subStateNode, - stateValue[subStateKey] + stateValue[subStateKey]! ); return allSubStateNodes.concat(subStateNodes); @@ -684,7 +684,7 @@ export function transitionCompoundNode< const childStateNode = getStateNode(stateNode, subStateKeys[0]); const next = transitionNode( childStateNode, - stateValue[subStateKeys[0]], + stateValue[subStateKeys[0]]!, snapshot, event ); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index b06a4e61f9..2e4dedfa2c 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -295,7 +295,7 @@ export type Actions< export type StateKey = string | AnyMachineSnapshot; export interface StateValueMap { - [key: string]: StateValue; + [key: string]: StateValue | undefined; } /** @@ -2352,21 +2352,19 @@ export type ToChildren = // or maybe even `TActor["logic"]` since it's possible to configure `{ src: string; logic: SomeConcreteLogic }` // TODO: consider adding `| undefined` here Record - : Compute< - ToConcreteChildren & - { - include: { - [id: string]: TActor extends any - ? ActorRefFrom | undefined - : never; - }; - exclude: {}; - }[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 + : ToConcreteChildren & + { + include: { + [id: string]: TActor extends any + ? ActorRefFrom | undefined + : never; + }; + exclude: {}; + }[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 + ? 'include' + : string extends TActor['id'] ? 'include' - : string extends TActor['id'] - ? 'include' - : 'exclude'] - >; + : 'exclude']; export type StateSchema = { states?: Record; diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index d30acabfd2..900e0e9265 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -47,7 +47,7 @@ export function matchesState( return false; } - return matchesState(parentStateValue[key], childStateValue[key]); + return matchesState(parentStateValue[key]!, childStateValue[key]!); }); }