Function: typedSpec()
API / @xmachines/play-actor / typedSpec
function typedSpec(spec): PlaySpec;Defined in: packages/play-actor/src/abstract-actor.ts:91
The identity helper gives a view spec literal the type PlaySpec at the
definition site. The compiler therefore checks the spec, and the IDE completes it.
The XState meta field has the type Record<string, unknown>. TypeScript
therefore infers no spec shape from the context. typedSpec(...) is the
mechanism that starts the check where you write the spec. The parameter holds no
viewKey: the derivation stamps that field, and it overwrites a value from an
author without a notice. Therefore the compiler refuses a viewKey here.
The check of an excess property works on an inline object literal only. For a
spec in a variable, or for a spec from a spread, write satisfies PlaySpec at
the literal instead.
At run time this function does nothing: it returns the spec object without a change.
Parameters
| Parameter | Type |
|---|---|
spec | Omit<PlaySpec, "viewKey"> |
Returns
Example
meta: { view: typedSpec({ root: "root", elements: { root: { type: "Dashboard", props: { username: { $state: "/context/username" } }, children: [], }, }, }),}