Function: typedSpec()
API / @xmachines/play-actor / typedSpec
function typedSpec<TContext>(spec): PlaySpec;Defined in: packages/play-actor/src/abstract-actor.ts:83
Identity helper that constrains a PlaySpec object’s contextProps to keys
of a specific machine context type, giving compile-time validation and IDE
autocomplete at the definition site.
XState’s meta field is typed as Record<string, unknown>, so TypeScript
cannot infer the constraint from context. typedSpec<MyCtx>(...) is the
opt-in mechanism that activates enforcement where the spec is written.
At runtime this is a no-op — the spec object is returned unchanged.
Type Parameters
| Type Parameter |
|---|
TContext extends object |
Parameters
| Parameter | Type |
|---|---|
spec | Omit<PlaySpec, "contextProps"> & object |
Returns
Example
interface DashboardCtx { username: string; params: Record<string, string>; query: Record<string, string>;}
meta: { view: typedSpec<DashboardCtx>({ root: "root", contextProps: ["username"], // ✓ key of DashboardCtx // contextProps: ["usernaem"], // ✗ compile error elements: { root: { type: "Dashboard", props: {}, children: [] } }, }),}