diff --git a/packages/core/src/State.ts b/packages/core/src/State.ts index f3641ceb5c..b0fc98e2fc 100644 --- a/packages/core/src/State.ts +++ b/packages/core/src/State.ts @@ -18,14 +18,14 @@ import type { EventObject, HistoryValue, MachineContext, - PersistedMachineState, Prop, StateConfig, StateValue, TODO, AnyActorRef, Compute, - EventDescriptor + EventDescriptor, + Snapshot } from './types.ts'; import { flatten, matchesState } from './utils.ts'; @@ -300,27 +300,11 @@ export function getPersistedState< TOutput, TResolvedTypesMeta > -): PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta -> { +): Snapshot { const { configuration, tags, machine, children, context, ...jsonValues } = state; - const childrenJson: Partial< - PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >['children'] - > = {}; + const childrenJson: Record = {}; for (const id in children) { const child = children[id] as any; @@ -328,25 +312,18 @@ export function getPersistedState< throw new Error('An inline child actor cannot be persisted.'); } childrenJson[id as keyof typeof childrenJson] = { - state: child.getPersistedState?.(), + state: child.getPersistedState(), src: child.src }; } - return { + const persisted = { ...jsonValues, - // TODO: this makes `PersistedMachineState`'s type kind of a lie - // it doesn't truly use `TContext` but rather some kind of a derived form of it context: persistContext(context) as any, children: childrenJson - } as PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >; + }; + + return persisted; } function persistContext(contextPart: Record) { diff --git a/packages/core/src/StateMachine.ts b/packages/core/src/StateMachine.ts index a59ab9f26e..426441ab42 100644 --- a/packages/core/src/StateMachine.ts +++ b/packages/core/src/StateMachine.ts @@ -37,7 +37,6 @@ import type { StateMachineDefinition, StateValue, TransitionDefinition, - PersistedMachineState, ParameterizedObject, AnyActorContext, AnyEventObject, @@ -45,7 +44,8 @@ import type { AnyActorRef, Equals, TODO, - SnapshotFrom + SnapshotFrom, + Snapshot } from './types.ts'; import { isErrorActorEvent, resolveReferencedActor } from './utils.ts'; import { $$ACTOR_TYPE, createActor } from './interpreter.ts'; @@ -114,14 +114,6 @@ export class StateMachine< >, TEvent, TInput, - PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >, TODO > { @@ -541,14 +533,7 @@ export class StateMachine< TOutput, TResolvedTypesMeta > - ): PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - > { + ) { return getPersistedState(state); } @@ -577,14 +562,7 @@ export class StateMachine< } public restoreState( - snapshot: PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >, + snapshot: Snapshot, _actorCtx: ActorContext< MachineSnapshot< TContext, @@ -605,10 +583,14 @@ export class StateMachine< TResolvedTypesMeta > { const children: Record = {}; + const snapshotChildren: Record< + string, + { src: string; state: Snapshot } + > = (snapshot as any).children; - Object.keys(snapshot.children).forEach((actorId) => { + Object.keys(snapshotChildren).forEach((actorId) => { const actorData = - snapshot.children[actorId as keyof typeof snapshot.children]; + snapshotChildren[actorId as keyof typeof snapshotChildren]; const childState = actorData.state; const src = actorData.src; @@ -630,7 +612,7 @@ export class StateMachine< }); const restoredSnapshot = this.createState( - new State({ ...snapshot, children }, this) as any + new State({ ...(snapshot as any), children }, this) as any ); let seen = new Set(); diff --git a/packages/core/src/actors/callback.ts b/packages/core/src/actors/callback.ts index df666511b5..78e009a737 100644 --- a/packages/core/src/actors/callback.ts +++ b/packages/core/src/actors/callback.ts @@ -6,8 +6,7 @@ import { ActorSystem, ActorRefFrom, TODO, - Snapshot, - HomomorphicOmit + Snapshot } from '../types'; import { XSTATE_STOP } from '../constants.ts'; @@ -24,7 +23,6 @@ export type CallbackActorLogic< CallbackSnapshot, TEvent, TInput, - HomomorphicOmit, '_receivers' | '_dispose'>, ActorSystem >; @@ -120,7 +118,7 @@ export function fromCallback( }; }, getPersistedState: ({ _dispose, _receivers, ...rest }) => rest, - restoreState: (state) => ({ + restoreState: (state: any) => ({ _receivers: new Set(), _dispose: undefined, ...state diff --git a/packages/core/src/actors/observable.ts b/packages/core/src/actors/observable.ts index 1ee439068b..a676bfe1c7 100644 --- a/packages/core/src/actors/observable.ts +++ b/packages/core/src/actors/observable.ts @@ -6,8 +6,7 @@ import { Subscription, AnyActorSystem, ActorRefFrom, - Snapshot, - HomomorphicOmit + Snapshot } from '../types'; export type ObservableSnapshot = Snapshot & { @@ -16,16 +15,10 @@ export type ObservableSnapshot = Snapshot & { _subscription: Subscription | undefined; }; -export type ObservablePersistedState = HomomorphicOmit< - ObservableSnapshot, - '_subscription' ->; - export type ObservableActorLogic = ActorLogic< ObservableSnapshot, { type: string; [k: string]: unknown }, TInput, - ObservablePersistedState, AnyActorSystem >; @@ -123,7 +116,7 @@ export function fromObservable( }, getPersistedState: ({ _subscription, ...state }) => state, restoreState: (state) => ({ - ...state, + ...(state as any), _subscription: undefined }) }; @@ -224,7 +217,7 @@ export function fromEventObservable( }); }, getPersistedState: ({ _subscription, ...state }) => state, - restoreState: (state) => ({ + restoreState: (state: any) => ({ ...state, _subscription: undefined }) diff --git a/packages/core/src/actors/promise.ts b/packages/core/src/actors/promise.ts index de9312e1f0..9f8fd8d82d 100644 --- a/packages/core/src/actors/promise.ts +++ b/packages/core/src/actors/promise.ts @@ -31,7 +31,6 @@ export type PromiseActorLogic = ActorLogic< PromiseSnapshot, { type: string; [k: string]: unknown }, TInput, // input - PromiseSnapshot, // persisted state ActorSystem >; @@ -120,7 +119,7 @@ export function fromPromise( }; }, getPersistedState: (state) => state, - restoreState: (state) => state + restoreState: (state: any) => state }; return logic; diff --git a/packages/core/src/actors/transition.ts b/packages/core/src/actors/transition.ts index d994fbe154..c2581ca21b 100644 --- a/packages/core/src/actors/transition.ts +++ b/packages/core/src/actors/transition.ts @@ -16,13 +16,7 @@ export type TransitionActorLogic< TContext, TEvent extends EventObject, TInput -> = ActorLogic< - TransitionSnapshot, - TEvent, - TInput, - TransitionSnapshot, - AnyActorSystem ->; +> = ActorLogic, TEvent, TInput, AnyActorSystem>; export type TransitionActorRef< TContext, @@ -81,6 +75,6 @@ export function fromTransition< }; }, getPersistedState: (state) => state, - restoreState: (state) => state + restoreState: (state: any) => state }; } diff --git a/packages/core/src/interpreter.ts b/packages/core/src/interpreter.ts index e684e02deb..93158ec0f6 100644 --- a/packages/core/src/interpreter.ts +++ b/packages/core/src/interpreter.ts @@ -20,10 +20,10 @@ import type { AnyActorLogic, AnyStateMachine, EventFromLogic, - PersistedStateFrom, SnapshotFrom, AnyActorRef, - DoneActorEvent + DoneActorEvent, + Snapshot } from './types.ts'; import { ActorRef, @@ -543,8 +543,8 @@ export class Actor }; } - public getPersistedState(): PersistedStateFrom | undefined { - return this.logic.getPersistedState?.(this._state); + public getPersistedState(): Snapshot { + return this.logic.getPersistedState(this._state); } public [symbolObservable](): InteropSubscribable> { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 63abc8c884..0724218c8c 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -127,7 +127,6 @@ export type InputFrom = T extends StateMachine< infer _TSnapshot, infer _TEvent, infer TInput, - infer _TPersisted, infer _TSystem > ? TInput @@ -137,7 +136,6 @@ export type OutputFrom = T extends ActorLogic< infer TSnapshot, infer _TEvent, infer _TInput, - infer _TPersisted, infer _TSystem > ? (TSnapshot & { status: 'done' })['output'] @@ -1804,8 +1802,7 @@ export interface ActorRef< // TODO: should this be optional? start?: () => void; getSnapshot: () => TSnapshot; - // TODO: this should return some sort of TPersistedState, not any - getPersistedState?: () => any; + getPersistedState: () => Snapshot; stop: () => void; toJSON?: () => any; // TODO: figure out how to hide this externally as `sendTo(ctx => ctx.actorRef._parent._parent._parent._parent)` shouldn't be allowed @@ -1857,7 +1854,6 @@ export type ActorRefFrom = ReturnTypeOrValue extends infer R infer TSnapshot, infer TEvent, infer _TInput, - infer _TPersisted, infer _TSystem > ? ActorRef @@ -1895,14 +1891,6 @@ export type InterpreterFrom< >, TEvent, TInput, - PersistedMachineState< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >, ActorSystem > > @@ -1992,10 +1980,6 @@ export interface ActorLogic< TSnapshot extends Snapshot, TEvent extends EventObject, TInput = unknown, - /** - * Serialized internal state used for persistence & restoration - */ - TPersisted = TSnapshot, TSystem extends ActorSystem = ActorSystem > { config?: unknown; @@ -2009,21 +1993,20 @@ export interface ActorLogic< input: TInput ) => TSnapshot; restoreState?: ( - persistedState: TPersisted, + persistedState: Snapshot, actorCtx: ActorContext ) => TSnapshot; start?: (state: TSnapshot, actorCtx: ActorContext) => void; /** * @returns Persisted state */ - getPersistedState?: (state: TSnapshot) => TPersisted; + getPersistedState: (state: TSnapshot) => Snapshot; } export type AnyActorLogic = ActorLogic< any, // snapshot any, // event any, // input - any, // persisted state any // system >; @@ -2045,36 +2028,18 @@ export type SnapshotFrom = ReturnTypeOrValue extends infer R infer _TResolvedTypesMeta > ? StateFrom - : R extends ActorLogic + : R extends ActorLogic ? ReturnType : R extends ActorContext ? TSnapshot : never : never; -export type EventFromLogic> = - TLogic extends ActorLogic< - infer _, - infer TEvent, - infer __, - infer _____, - infer ______ - > +export type EventFromLogic> = + TLogic extends ActorLogic ? TEvent : never; -export type PersistedStateFrom< - TLogic extends ActorLogic -> = TLogic extends ActorLogic< - infer _TSnapshot, - infer _TEvent, - infer _TInput, - infer TPersisted, - infer _TSystem -> - ? TPersisted - : never; - type ResolveEventType = ReturnTypeOrValue extends infer R ? R extends StateMachine< infer _TContext, @@ -2202,29 +2167,3 @@ export interface ActorSystem { } export type AnyActorSystem = ActorSystem; - -export type PersistedMachineState< - TContext extends MachineContext, - TEvent extends EventObject, - TActor extends ProvidedActor, - TTag extends string, - TOutput, - TResolvedTypesMeta = TypegenDisabled -> = HomomorphicPick< - MachineSnapshot, - 'value' | 'output' | 'error' | 'context' | 'status' | 'historyValue' -> & { - children: { - [K in keyof MachineSnapshot< - TContext, - TEvent, - TActor, - TTag, - TOutput, - TResolvedTypesMeta - >['children']]: { - state: any; // TODO: fix (should be state from actorref) - src?: string; - }; - }; -}; diff --git a/packages/core/test/actor.test.ts b/packages/core/test/actor.test.ts index ae7ae9e9b0..08d59412a2 100644 --- a/packages/core/test/actor.test.ts +++ b/packages/core/test/actor.test.ts @@ -1133,7 +1133,8 @@ describe('actors', () => { status: 'active', output: undefined, error: undefined - }) + }), + getPersistedState: (s) => s }; const pingMachine = createMachine({ diff --git a/packages/core/test/actorLogic.test.ts b/packages/core/test/actorLogic.test.ts index 8b6f80b482..60616e46b4 100644 --- a/packages/core/test/actorLogic.test.ts +++ b/packages/core/test/actorLogic.test.ts @@ -598,7 +598,7 @@ describe('machine logic', () => { const persistedState = actor.getPersistedState()!; - expect(persistedState.children.a.state).toMatchInlineSnapshot(` + expect((persistedState as any).children.a.state).toMatchInlineSnapshot(` { "error": undefined, "input": undefined, @@ -607,7 +607,7 @@ describe('machine logic', () => { } `); - expect(persistedState.children.b.state).toEqual( + expect((persistedState as any).children.b.state).toEqual( expect.objectContaining({ context: { count: 55 @@ -724,7 +724,7 @@ describe('machine logic', () => { const actor = createActor(machine); - expect(actor.getPersistedState()?.children['child'].state).toEqual( + expect((actor.getPersistedState() as any).children['child'].state).toEqual( expect.objectContaining({ value: 'inner' }) @@ -772,9 +772,9 @@ describe('machine logic', () => { value: 'value' }); - const persisted = actor.getPersistedState(); + const persisted: any = actor.getPersistedState(); - delete persisted?.children['child']; + delete persisted.children['child']; const rehydratedActor = createActor(machine, { state: persisted }).start(); @@ -807,7 +807,9 @@ describe('machine logic', () => { const persistedState = actor.getPersistedState()!; - expect(persistedState.children.child.state.context).toEqual({ count: 42 }); + expect((persistedState as any).children.child.state.context).toEqual({ + count: 42 + }); const newActor = createActor(machine, { state: persistedState diff --git a/packages/core/test/invoke.test.ts b/packages/core/test/invoke.test.ts index 09701dfc69..cf756efef5 100644 --- a/packages/core/test/invoke.test.ts +++ b/packages/core/test/invoke.test.ts @@ -2268,7 +2268,8 @@ describe('invoke', () => { output: undefined, error: undefined, context: 0 - }) + }), + getPersistedState: (s) => s }; const countMachine = createMachine({ @@ -2308,7 +2309,8 @@ describe('invoke', () => { status: 'active', output: undefined, error: undefined - }) + }), + getPersistedState: (s) => s }; const pingMachine = createMachine({ diff --git a/packages/core/test/typeHelpers.test.ts b/packages/core/test/typeHelpers.test.ts index 8f37279ad6..aaabfe7722 100644 --- a/packages/core/test/typeHelpers.test.ts +++ b/packages/core/test/typeHelpers.test.ts @@ -363,7 +363,8 @@ describe('ActorRefFrom', () => { status: 'active', output: undefined, error: undefined - }) + }), + getPersistedState: (s) => s }; function acceptActorRef(actorRef: ActorRefFrom) { diff --git a/packages/xstate-graph/src/adjacency.ts b/packages/xstate-graph/src/adjacency.ts index fce4a8160a..2f743ea1d5 100644 --- a/packages/xstate-graph/src/adjacency.ts +++ b/packages/xstate-graph/src/adjacency.ts @@ -13,10 +13,9 @@ export function getAdjacencyMap< TSnapshot extends Snapshot, TEvent extends EventObject, TInput, - TPersisted = TSnapshot, TSystem extends ActorSystem = ActorSystem >( - logic: ActorLogic, + logic: ActorLogic, options: TraversalOptions ): AdjacencyMap { const { transition } = logic; diff --git a/packages/xstate-graph/src/pathFromEvents.ts b/packages/xstate-graph/src/pathFromEvents.ts index ae00e92c8d..900581b655 100644 --- a/packages/xstate-graph/src/pathFromEvents.ts +++ b/packages/xstate-graph/src/pathFromEvents.ts @@ -30,10 +30,9 @@ export function getPathsFromEvents< TSnapshot extends Snapshot, TEvent extends EventObject, TInput, - TPersisted = TSnapshot, TSystem extends ActorSystem = ActorSystem >( - logic: ActorLogic, + logic: ActorLogic, events: TEvent[], options?: TraversalOptions ): Array> { diff --git a/packages/xstate-react/test/createActorContext.test.tsx b/packages/xstate-react/test/createActorContext.test.tsx index 2f53d98db7..8b44703ed0 100644 --- a/packages/xstate-react/test/createActorContext.test.tsx +++ b/packages/xstate-react/test/createActorContext.test.tsx @@ -1,4 +1,4 @@ -import { createMachine, assign, fromPromise, PersistedStateFrom } from 'xstate'; +import { createMachine, assign, fromPromise, Snapshot } from 'xstate'; import { fireEvent, screen, render, waitFor } from '@testing-library/react'; import { useSelector, createActorContext, shallowEqual } from '../src'; @@ -391,14 +391,13 @@ describe('createActorContext', () => { } }); const SomeContext = createActorContext(machine); - let persistedState: PersistedStateFrom | undefined = - undefined; + let persistedState: Snapshot | undefined = undefined; const Component = () => { const actorRef = SomeContext.useActorRef(); const state = SomeContext.useSelector((state) => state); - persistedState = actorRef.getPersistedState?.(); + persistedState = actorRef.getPersistedState(); return (
{ const Fetcher: React.FC<{ onFetch: () => Promise; - persistedState?: PersistedMachineState; + persistedState?: Snapshot; }> = ({ onFetch = () => { return new Promise((res) => res('some data')); diff --git a/packages/xstate-react/test/useSelector.test.tsx b/packages/xstate-react/test/useSelector.test.tsx index 6ce4383125..e8f01cda9d 100644 --- a/packages/xstate-react/test/useSelector.test.tsx +++ b/packages/xstate-react/test/useSelector.test.tsx @@ -340,18 +340,7 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => { it('should immediately render snapshot of initially spawned custom actor', () => { const createCustomActor = (latestValue: string) => - createActor({ - transition: (s) => s, - subscribe: () => { - return { unsubscribe: () => {} }; - }, - getInitialState: () => ({ - status: 'active', - output: undefined, - error: undefined, - context: latestValue - }) - }); + createActor(fromTransition((s) => s, latestValue)); const parentMachine = createMachine({ types: { @@ -486,18 +475,7 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => { it("should render snapshot value when actor doesn't emit anything", () => { const createCustomActor = (latestValue: string) => - createActor({ - transition: (s) => s, - subscribe: () => { - return { unsubscribe: () => {} }; - }, - getInitialState: () => ({ - status: 'active', - output: undefined, - error: undefined, - context: latestValue - }) - }); + createActor(fromTransition((s) => s, latestValue)); const parentMachine = createMachine({ types: { @@ -527,18 +505,7 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => { it('should render snapshot state when actor changes', () => { const createCustomActor = (latestValue: string) => - createActor({ - transition: (s) => s, - subscribe: () => { - return { unsubscribe: () => {} }; - }, - getInitialState: () => ({ - status: 'active', - output: undefined, - error: undefined, - context: latestValue - }) - }); + createActor(fromTransition((s) => s, latestValue)); const actor1 = createCustomActor('foo'); const actor2 = createCustomActor('bar'); @@ -562,20 +529,8 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => { }); it("should keep rendering a new selected value after selector change when the actor doesn't emit", async () => { - const actor = createActor({ - transition: (s) => s, - subscribe: () => { - return { unsubscribe: () => {} }; - }, - getInitialState: () => { - return { - status: 'active', - output: undefined, - error: undefined, - context: undefined - }; - } - }); + const actor = createActor(fromTransition((s) => s, undefined)); + actor.subscribe = () => ({ unsubscribe: () => {} }); const App = ({ selector }: { selector: any }) => { const [, forceRerender] = React.useState(0); diff --git a/packages/xstate-solid/src/createSpawn.ts b/packages/xstate-solid/src/createSpawn.ts index 6fae909b34..5e04e146bb 100644 --- a/packages/xstate-solid/src/createSpawn.ts +++ b/packages/xstate-solid/src/createSpawn.ts @@ -11,11 +11,8 @@ import { export function createSpawn< TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted ->( - logic: ActorLogic -): ActorRef { + TInput +>(logic: ActorLogic): ActorRef { const actorRef = createActor(logic); if (!isServer) { diff --git a/packages/xstate-solid/test/useActor.test.tsx b/packages/xstate-solid/test/useActor.test.tsx index fa4dc0d1cd..b584693fc0 100644 --- a/packages/xstate-solid/test/useActor.test.tsx +++ b/packages/xstate-solid/test/useActor.test.tsx @@ -7,7 +7,8 @@ import { ActorRef, ActorRefFrom, createActor, - Snapshot + Snapshot, + fromTransition } from 'xstate'; import { fireEvent, screen, render, waitFor } from 'solid-testing-library'; import { @@ -23,15 +24,7 @@ import { import { createStore, reconcile } from 'solid-js/store'; const createSimpleActor = (value: T) => - createActor({ - transition: (s: Snapshot & { context: T }) => s, - getInitialState: () => ({ - status: 'active', - output: undefined, - error: undefined, - context: value - }) - }); + createActor(fromTransition((s) => s, value)); describe('useActor', () => { it('initial invoked actor should be immediately available', (done) => { @@ -653,17 +646,7 @@ describe('useActor', () => { }); it('should provide value from `actor.getSnapshot()` immediately', () => { - const simpleActor = createActor({ - transition: (s: Snapshot & { context: number }) => s, - getInitialState: () => { - return { - status: 'active', - output: undefined, - error: undefined, - context: 42 - }; - } - }); + const simpleActor = createActor(fromTransition((s) => s, 42)); const Test = () => { const [state] = useActor(simpleActor); diff --git a/packages/xstate-solid/test/useMachine.test.tsx b/packages/xstate-solid/test/useMachine.test.tsx index a0819d016d..82ca138238 100644 --- a/packages/xstate-solid/test/useMachine.test.tsx +++ b/packages/xstate-solid/test/useMachine.test.tsx @@ -16,10 +16,6 @@ import { Actor, ActorLogicFrom, ActorStatus, - EventObject, - MachineContext, - PersistedMachineState, - ProvidedActor, assign, createActor, createMachine, diff --git a/packages/xstate-test/src/TestModel.ts b/packages/xstate-test/src/TestModel.ts index ba9ab0c359..100ce867d4 100644 --- a/packages/xstate-test/src/TestModel.ts +++ b/packages/xstate-test/src/TestModel.ts @@ -46,8 +46,7 @@ function isStateLike(state: any): state is AnyState { export class TestModel< TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted + TInput > { public options: TestModelOptions; public defaultTraversalOptions?: TraversalOptions; @@ -69,7 +68,7 @@ export class TestModel< } constructor( - public logic: ActorLogic, + public logic: ActorLogic, options?: Partial> ) { this.options = { @@ -79,7 +78,7 @@ export class TestModel< } public getPaths( - pathGenerator: PathGenerator, + pathGenerator: PathGenerator, options?: Partial> ): Array> { const paths = pathGenerator(this.logic, this.resolveOptions(options)); diff --git a/packages/xstate-test/src/machine.ts b/packages/xstate-test/src/machine.ts index 408cb7c962..5a2b92e6c1 100644 --- a/packages/xstate-test/src/machine.ts +++ b/packages/xstate-test/src/machine.ts @@ -130,7 +130,7 @@ export function createTestModel( options?: Partial< TestModelOptions, EventFrom> > -): TestModel, EventFrom, unknown, unknown> { +): TestModel, EventFrom, unknown> { validateMachine(machine); const serializeEvent = (options?.serializeEvent ?? simpleStringify) as ( @@ -143,8 +143,7 @@ export function createTestModel( const testModel = new TestModel< SnapshotFrom, EventFrom, - unknown, - any + unknown >(machine as any, { serializeState: (state, event, prevState) => { // Only consider the `state` if `serializeTransition()` is opted out (empty string) diff --git a/packages/xstate-test/src/pathGenerators.ts b/packages/xstate-test/src/pathGenerators.ts index 25ac494399..9c2ba69e80 100644 --- a/packages/xstate-test/src/pathGenerators.ts +++ b/packages/xstate-test/src/pathGenerators.ts @@ -6,9 +6,8 @@ export const createShortestPathsGen = < TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted - >(): PathGenerator => + TInput + >(): PathGenerator => (logic, defaultOptions) => { const paths = getShortestPaths(logic, defaultOptions); @@ -19,9 +18,8 @@ export const createSimplePathsGen = < TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted - >(): PathGenerator => + TInput + >(): PathGenerator => (logic, defaultOptions) => { const paths = getSimplePaths(logic, defaultOptions); diff --git a/packages/xstate-test/src/types.ts b/packages/xstate-test/src/types.ts index eb93f65b65..47cb36a0d4 100644 --- a/packages/xstate-test/src/types.ts +++ b/packages/xstate-test/src/types.ts @@ -21,11 +21,10 @@ type TODO = any; export type GetPathsOptions< TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted + TInput > = Partial< TraversalOptions & { - pathGenerator?: PathGenerator; + pathGenerator?: PathGenerator; } >; @@ -205,9 +204,8 @@ export type TestTransitionsConfig< export type PathGenerator< TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted + TInput > = ( - behavior: ActorLogic, + behavior: ActorLogic, options: TraversalOptions ) => Array>; diff --git a/packages/xstate-test/test/testUtils.ts b/packages/xstate-test/test/testUtils.ts index e4d42b49c2..dd75ac694e 100644 --- a/packages/xstate-test/test/testUtils.ts +++ b/packages/xstate-test/test/testUtils.ts @@ -5,10 +5,9 @@ import { TestParam, TestPath } from '../src/types'; async function testModel< TSnapshot extends Snapshot, TEvent extends EventObject, - TInput, - TPersisted + TInput >( - model: TestModel, + model: TestModel, params: TestParam ) { for (const path of model.getShortestPaths()) {