Editor
, Element
and Text
types). If you need to support more than one document model, see the section Multiple Document Models.CustomTypes
, annotate useState
, and annotate the editor's initial state when using TypeScript or Slate will display typing errors.node.type
, you may see the error Property 'type' does not exist on type 'Node'
. To fix this, you need to add code like Element.isElement(node) && node.type === 'paragraph'
. This is necessary because a Node
can be an Element
or Text
and Text
does not have a type
property.Editor
. Make sure to define the CustomType for Editor
as BaseEditor & ...
. It should not be Editor & ...
Editor
, Element
and Text
TypesElement
or Text
type, extend the CustomTypes
interface in the slate
module like this.Descendant[]
.Element
and Text
TypesCustomTypes
interface, best practice is to define and export each type separately so that you can reference individual types like a ParagraphElement
.CustomText
is equal to FormattedText
but in a real editor, there can be more types of text like text in a code block which may not allow formatting for example.ParagraphElement | HeadingElement
). This allows a user to narrow a type. If presented with code like if (node.type === 'paragraph') { ... }
the inside of the block, will narrow the type of node to ParagraphElement
.interface
.Selection
Range
Point
packages/slate-react/src/custom-types.ts
in the slate repository.