Function: typedSpec()
API / @xmachines/play-view / index / typedSpec
function typedSpec(spec): ViewMeta;Defined in: packages/play-view/src/view-types.ts:126
The identity helper gives a view spec literal the type ViewMeta 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. ViewMeta holds no
viewKey and no viewParts: the derivation stamps those fields, and it overwrites
a value from an author without a notice. Therefore the compiler refuses them 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 ViewMeta at
the literal instead.
At run time this function does nothing: it returns the spec object without a change.
Parameters
| Parameter | Type |
|---|---|
spec | ViewMeta |
Returns
Example
meta: { view: typedSpec({ root: "root", elements: { root: { type: "Dashboard", props: { username: { $state: "/context/username" } }, children: [], }, }, }),}