Skip to main content

SerializedPartialNode

type

A node of a compact document read without knowing its type, which is every child: a node cannot declare what kind of children it accepts, so any node may appear under any element and there is no type to name their properties from. The outer node of a SerializedPartial is refinable — you know what you asked for — and its children never are. So the framework properties are named and a node's own arrive as `unknown`, which a reader narrows by `type` as it would any untrusted JSON. `children` and `$slots` recurse, because a compact export applies to a subtree exactly as it does to its root: naming `SerializedPartial<SerializedLexicalNode>` for them instead would leave a nested element unable to carry the children it has. The index signature is what lets a document be *written*. Without it every node-specific property on a child is an excess-property error, so `editor.parseEditorState({root: {children: [{children: [{text: 'hi', type: 'text'}], …}], …}})` — a hand-authored initial state, the most ordinary literal a caller writes — does not compile, and neither does a fixture, a migration script, or `$parseSerializedNode` on a literal. Closing the type was tried for the misspelling it would catch; excess-property checking fires only on fresh literals, and everything arriving at load comes from `JSON.parse`, so it caught no misspelling that mattered and cost every correct property. Flow's counterpart is inexact for the same reason.

type SerializedPartialNode = { /** The one property every node carries and a reader narrows by. */ type: string; /** Omitted by a compact export, like every other restorable property. */ version?: number; /** Node state, parsed by the same rules whatever the node turns out to be. */ [NODE_STATE_KEY]?: Record<string, unknown>; /** A slot holds a node subtree, so it relaxes exactly as `children` do. */ $slots?: Record<string, SerializedPartialNode | SerializedLexicalNode>; /** Present when the node is an element; the same form all the way down. */ children?: SerializedPartialNode[]; /** A node's own properties: there is no type here to name them from. */ [key: string]: unknown; }

Import

import { SerializedPartialNode } from '@modular/sdk/editor';