Skip to main content

LexicalParseJSON

type

The shape LexicalNode.updateFromJSON accepts for a node whose serialized type is `S`, as a schema-driven parser faces it: every node-specific property optional (a compact export omits a default-valued one, and an older document predates a newer one) and `unknown`, with `type`, `version` and `children` dropped. `unknown`, because this is the untrusted-JSON boundary and a parser here is *total*: it validates every property against the schema's domain and substitutes a default for anything outside it. Typing a property as what it parses *to* would claim the caller has already done that validation, which is both untrue and narrower than what is accepted — a schema reads more than it writes wherever it has an alias table or reads a number spelled as a string, so `format: 'bold'` and `width: '640'` are valid input that the narrower type rejected. The property *names* stay, so a misspelled one is still an excess-property error. NodeState and slots keep their declared shapes: neither is a schema-declared property, and each is read structurally by the code that applies it rather than validated against a domain. A node that declares a serialization schema narrows both JSON methods to its own serialized type by declaration merging, which is the one thing a schema cannot do for it: ```ts export interface MarkNode { exportJSON(compact?: false): SerializedMarkNode; exportJSON(compact: boolean): SerializedPartial<SerializedMarkNode>; updateFromJSON(serializedNode: LexicalParseJSON<SerializedMarkNode>): this; } ``` A hand-written override that reads its properties typed uses LexicalUpdateJSON instead, as it always has.

type LexicalParseJSON<S extends SerializedLexicalNode> = Pick<SerializedPartial<S>, Extract<keyof SerializedPartial<S>, typeof NODE_STATE_KEY | '$slots'>> & { [K in keyof Omit<SerializedPartial<S>, '$slots' | 'children' | 'type' | typeof NODE_STATE_KEY | 'version'>]?: unknown; }

Import

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