Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Remove typegen types #4949

Merged
merged 25 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { $$ACTOR_TYPE } from './createActor.ts';
import type { StateNode } from './StateNode.ts';
import type { StateMachine } from './StateMachine.ts';
import { getStateValue } from './stateUtils.ts';
import { TypegenDisabled } from './typegenTypes.ts';
import type {
ProvidedActor,
AnyMachineSnapshot,
Expand Down
38 changes: 21 additions & 17 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
transitionNode
} from './stateUtils.ts';
import { AnyActorSystem } from './system.ts';
import { ResolveTypegenMeta, TypegenDisabled } from './typegenTypes.ts';
import { ResolveTypegenMeta } from './typegenTypes.ts';
import type {
ActorLogic,
ActorScope,
Expand Down Expand Up @@ -66,17 +66,7 @@ export class StateMachine<
TInput,
TOutput,
TEmitted extends EventObject = EventObject, // TODO: remove default
TMeta extends MetaObject = MetaObject,
TResolvedTypesMeta = ResolveTypegenMeta<
TypegenDisabled,
DoNotInfer<TEvent>,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>
TMeta extends MetaObject = MetaObject
> implements
ActorLogic<
MachineSnapshot<
Expand Down Expand Up @@ -188,8 +178,15 @@ export class StateMachine<
public provide(
implementations: InternalMachineImplementations<
TContext,
TResolvedTypesMeta,
true
ResolveTypegenMeta<
DoNotInfer<TEvent>,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>
>
): StateMachine<
TContext,
Expand All @@ -204,8 +201,7 @@ export class StateMachine<
TInput,
TOutput,
TEmitted,
TMeta, // TMeta
TResolvedTypesMeta
TMeta
> {
const { actions, guards, actors, delays } = this.implementations;

Expand Down Expand Up @@ -623,5 +619,13 @@ export class StateMachine<
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
__TResolvedTypesMeta!: TResolvedTypesMeta;
__TResolvedTypesMeta!: ResolveTypegenMeta<
DoNotInfer<TEvent>,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>;
}
4 changes: 2 additions & 2 deletions packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ export class StateNode<
any, // action
any, // guard
any, // delay
any, // state value
any, // tag
any, // input
any, // output
any, // emitted
any, // TMeta
any // typegen
any // meta
>;
/**
* The meta data associated with this state node, which will be returned in State instances.
Expand Down
60 changes: 9 additions & 51 deletions packages/core/src/createMachine.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { StateMachine } from './StateMachine.ts';
import {
ResolveTypegenMeta,
TypegenConstraint,
TypegenDisabled
} from './typegenTypes.ts';
import { ResolveTypegenMeta } from './typegenTypes.ts';
import {
AnyActorRef,
EventObject,
Expand All @@ -16,7 +12,6 @@ import {
MachineTypes,
NonReducibleUnknown,
ParameterizedObject,
Prop,
ProvidedActor,
StateValue,
ToChildren,
Expand Down Expand Up @@ -122,7 +117,7 @@ export function createMachine<
// it's important to have at least one default type parameter here
// it allows us to benefit from contextual type instantiation as it makes us to pass the hasInferenceCandidatesOrDefault check in the compiler
// we should be able to remove this when we start inferring TConfig, with it we'll always have an inference candidate
TTypesMeta extends TypegenConstraint = TypegenDisabled
_ = any
>(
config: {
types?: MachineTypes<
Expand All @@ -136,8 +131,7 @@ export function createMachine<
TInput,
TOutput,
TEmitted,
TMeta,
TTypesMeta
TMeta
>;
schemas?: unknown;
} & MachineConfig<
Expand All @@ -151,21 +145,11 @@ export function createMachine<
TInput,
TOutput,
TEmitted,
TMeta,
TTypesMeta
TMeta
>,
implementations?: InternalMachineImplementations<
TContext,
ResolveTypegenMeta<
TTypesMeta,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>
ResolveTypegenMeta<TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>
>
): StateMachine<
TContext,
Expand All @@ -175,37 +159,12 @@ export function createMachine<
TAction,
TGuard,
TDelay,
'matchesStates' extends keyof TTypesMeta
? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>>
: StateValue,
Prop<
ResolveTypegenMeta<
TTypesMeta,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>['resolved'],
'tags'
> &
string,
StateValue,
TTag & string,
TInput,
TOutput,
TEmitted,
TMeta, // TMeta
ResolveTypegenMeta<
TTypesMeta,
TEvent,
TActor,
TAction,
TGuard,
TDelay,
TTag,
TEmitted
>
TMeta // TMeta
> {
return new StateMachine<
any,
Expand All @@ -220,7 +179,6 @@ export function createMachine<
any,
any,
any, // TEmitted
any, // TMeta
any
any // TMeta
>(config as any, implementations as any);
}
26 changes: 3 additions & 23 deletions packages/core/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StateMachine } from './StateMachine';
import { createMachine } from './createMachine';
import { GuardPredicate } from './guards';
import { ResolveTypegenMeta, TypegenDisabled } from './typegenTypes';

import {
ActionFunction,
AnyActorRef,
Expand Down Expand Up @@ -196,17 +196,7 @@ export function setup<
TInput,
TOutput,
TEmitted,
TMeta,
ResolveTypegenMeta<
TypegenDisabled,
TEvent,
ToProvidedActor<TChildrenMap, TActors>,
ToParameterizedObject<TActions>,
ToParameterizedObject<TGuards>,
TDelay,
TTag,
TEmitted
>
TMeta
>
>(
config: TConfig
Expand All @@ -226,17 +216,7 @@ export function setup<
TInput,
TOutput,
TEmitted,
TMeta,
ResolveTypegenMeta<
TypegenDisabled,
TEvent,
ToProvidedActor<TChildrenMap, TActors>,
ToParameterizedObject<TActions>,
ToParameterizedObject<TGuards>,
TDelay,
TTag,
TEmitted
>
TMeta
>;
} {
return {
Expand Down
Loading
Loading