diff --git a/docs/api/locations.md b/docs/api/locations.md index 3325ef6d4..275374596 100644 --- a/docs/api/locations.md +++ b/docs/api/locations.md @@ -28,7 +28,7 @@ type Path = number[] interface Point { path: Path offset: number - [key: string]: any + [key: string]: unknown } ``` @@ -68,7 +68,7 @@ Options: `{affinity?: 'forward' | 'backward' | null}` interface Range { anchor: Point focus: Point - [key: string]: any + [key: string]: unknown } ``` diff --git a/docs/api/nodes.md b/docs/api/nodes.md index 6fea366d6..b18321f9b 100644 --- a/docs/api/nodes.md +++ b/docs/api/nodes.md @@ -123,7 +123,7 @@ interface Editor { selection: Range | null operations: Operation[] marks: Record | null - [key: string]: any + [key: string]: unknown // Schema-specific node behaviors. isInline: (element: Element) => boolean @@ -212,7 +212,7 @@ Apply an operation in the editor. ```typescript interface Element { children: Node[] - [key: string]: any + [key: string]: unknown } ``` @@ -237,7 +237,7 @@ Check if an element matches a set of `props`. Note: This checks custom propertie ```typescript interface Text { text: string, - [key: string]: any + [key: string]: unknown } ``` diff --git a/docs/concepts/01-interfaces.md b/docs/concepts/01-interfaces.md index e77443cfc..74f40a69b 100644 --- a/docs/concepts/01-interfaces.md +++ b/docs/concepts/01-interfaces.md @@ -5,7 +5,7 @@ Slate works with pure JSON objects. All it requires is that those JSON objects c ```ts interface Text { text: string - [key: string]: any + [key: string]: unknown } ``` @@ -22,7 +22,7 @@ To take another example, the `Element` node interface in Slate is: ```ts interface Element { children: Node[] - [key: string]: any + [key: string]: unknown } ``` diff --git a/docs/concepts/02-nodes.md b/docs/concepts/02-nodes.md index a43f36ab9..6454bbd1a 100644 --- a/docs/concepts/02-nodes.md +++ b/docs/concepts/02-nodes.md @@ -55,7 +55,7 @@ Elements make up the middle layers of a richtext document. They are the nodes th ```ts interface Element { children: Node[] - [key: string]: any + [key: string]: unknown } ``` @@ -126,7 +126,7 @@ Text nodes are the lowest-level nodes in the tree, containing the text content o ```ts interface Text { text: string - [key: string]: any + [key: string]: unknown } ``` diff --git a/docs/concepts/03-locations.md b/docs/concepts/03-locations.md index 795a121ed..f9b9f49fa 100644 --- a/docs/concepts/03-locations.md +++ b/docs/concepts/03-locations.md @@ -37,7 +37,7 @@ Points are slightly more specific than paths, and contain an `offset` into a spe interface Point { path: Path offset: number - [key: string]: any + [key: string]: unknown } ``` @@ -71,7 +71,7 @@ Ranges are a way to refer not just to a single point in the document, but to a w interface Range { anchor: Point focus: Point - [key: string]: any + [key: string]: unknown } ``` diff --git a/docs/concepts/06-editor.md b/docs/concepts/06-editor.md index 2657c2674..20e2e22bb 100644 --- a/docs/concepts/06-editor.md +++ b/docs/concepts/06-editor.md @@ -8,7 +8,7 @@ interface Editor { selection: Range | null operations: Operation[] marks: Record | null - [key: string]: any + [key: string]: unknown // Schema-specific node behaviors. isInline: (element: Element) => boolean diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 44fcc60ae..73b3452e4 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -708,7 +708,7 @@ export const Editable = (props: EditableProps) => { if (Hotkeys.isRedo(nativeEvent)) { event.preventDefault() - if (editor.redo) { + if (typeof editor.redo === 'function') { editor.redo() } @@ -718,7 +718,7 @@ export const Editable = (props: EditableProps) => { if (Hotkeys.isUndo(nativeEvent)) { event.preventDefault() - if (editor.undo) { + if (typeof editor.undo === 'function') { editor.undo() } diff --git a/packages/slate-react/src/components/leaf.tsx b/packages/slate-react/src/components/leaf.tsx index 8ab9fcd25..0d3e438a4 100644 --- a/packages/slate-react/src/components/leaf.tsx +++ b/packages/slate-react/src/components/leaf.tsx @@ -43,7 +43,7 @@ const Leaf = (props: { opacity: '0.333', }} > - {leaf.placeholder} + {leaf.placeholder as React.ReactNode} {children} diff --git a/packages/slate-react/src/components/slate.tsx b/packages/slate-react/src/components/slate.tsx index 49d5307b4..82b3caa0c 100644 --- a/packages/slate-react/src/components/slate.tsx +++ b/packages/slate-react/src/components/slate.tsx @@ -17,7 +17,7 @@ export const Slate = (props: { value: Node[] children: React.ReactNode onChange: (value: Node[]) => void - [key: string]: any + [key: string]: unknown }) => { const { editor, children, onChange, value, ...rest } = props const [key, setKey] = useState(0) diff --git a/packages/slate/src/interfaces/editor.ts b/packages/slate/src/interfaces/editor.ts index 782c36aed..5e48a5ff1 100755 --- a/packages/slate/src/interfaces/editor.ts +++ b/packages/slate/src/interfaces/editor.ts @@ -38,7 +38,7 @@ export interface Editor { selection: Range | null operations: Operation[] marks: Record | null - [key: string]: any + [key: string]: unknown // Schema-specific node behaviors. isInline: (element: Element) => boolean @@ -1332,7 +1332,7 @@ export const Editor = { // the operation was applied. parent.children.splice(index, 1) const truePath = Path.transform(path, op)! - const newParent = Node.get(editor, Path.parent(truePath)) + const newParent = Node.get(editor, Path.parent(truePath)) as Ancestor const newIndex = truePath[truePath.length - 1] newParent.children.splice(newIndex, 0, node) diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts index b63c9b428..34361e8c2 100755 --- a/packages/slate/src/interfaces/element.ts +++ b/packages/slate/src/interfaces/element.ts @@ -9,7 +9,7 @@ import { Editor, Node, Path } from '..' export interface Element { children: Node[] - [key: string]: any + [key: string]: unknown } export const Element = { diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index e8791fcd4..c9cc22088 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -5,7 +5,7 @@ export type InsertNodeOperation = { type: 'insert_node' path: Path node: Node - [key: string]: any + [key: string]: unknown } export type InsertTextOperation = { @@ -13,7 +13,7 @@ export type InsertTextOperation = { path: Path offset: number text: string - [key: string]: any + [key: string]: unknown } export type MergeNodeOperation = { @@ -22,21 +22,21 @@ export type MergeNodeOperation = { position: number target: number | null properties: Partial - [key: string]: any + [key: string]: unknown } export type MoveNodeOperation = { type: 'move_node' path: Path newPath: Path - [key: string]: any + [key: string]: unknown } export type RemoveNodeOperation = { type: 'remove_node' path: Path node: Node - [key: string]: any + [key: string]: unknown } export type RemoveTextOperation = { @@ -44,7 +44,7 @@ export type RemoveTextOperation = { path: Path offset: number text: string - [key: string]: any + [key: string]: unknown } export type SetNodeOperation = { @@ -52,25 +52,25 @@ export type SetNodeOperation = { path: Path properties: Partial newProperties: Partial - [key: string]: any + [key: string]: unknown } export type SetSelectionOperation = | { type: 'set_selection' - [key: string]: any + [key: string]: unknown properties: null newProperties: Range } | { type: 'set_selection' - [key: string]: any + [key: string]: unknown properties: Partial newProperties: Partial } | { type: 'set_selection' - [key: string]: any + [key: string]: unknown properties: Range newProperties: null } @@ -81,7 +81,7 @@ export type SplitNodeOperation = { position: number target: number | null properties: Partial - [key: string]: any + [key: string]: unknown } export type NodeOperation = diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index 20fce6759..971b6486c 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -12,7 +12,7 @@ import { Operation, Path } from '..' export interface Point { path: Path offset: number - [key: string]: any + [key: string]: unknown } export const Point = { diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index e2d60c681..5f53bfcd8 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -11,7 +11,7 @@ import { Operation, Path, Point, PointEntry } from '..' export interface Range { anchor: Point focus: Point - [key: string]: any + [key: string]: unknown } export const Range = { diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts index 80ca65f22..96eb750c4 100755 --- a/packages/slate/src/interfaces/text.ts +++ b/packages/slate/src/interfaces/text.ts @@ -9,7 +9,7 @@ import { Range } from '..' export interface Text { text: string - [key: string]: any + [key: string]: unknown } export const Text = { diff --git a/packages/slate/src/transforms/general.ts b/packages/slate/src/transforms/general.ts index cd6e7da00..5b170dfd4 100755 --- a/packages/slate/src/transforms/general.ts +++ b/packages/slate/src/transforms/general.ts @@ -10,7 +10,7 @@ import { Descendant, NodeEntry, Path, - Transforms, + Ancestor, } from '..' export const GeneralTransforms = { @@ -104,7 +104,7 @@ export const GeneralTransforms = { // the operation was applied. parent.children.splice(index, 1) const truePath = Path.transform(path, op)! - const newParent = Node.get(editor, Path.parent(truePath)) + const newParent = Node.get(editor, Path.parent(truePath)) as Ancestor const newIndex = truePath[truePath.length - 1] newParent.children.splice(newIndex, 0, node) diff --git a/packages/slate/src/transforms/node.ts b/packages/slate/src/transforms/node.ts index 03d1e4f3f..ec07de9c0 100644 --- a/packages/slate/src/transforms/node.ts +++ b/packages/slate/src/transforms/node.ts @@ -8,6 +8,8 @@ import { Range, Text, Transforms, + NodeEntry, + Ancestor, } from '..' export const NodeTransforms = { @@ -168,7 +170,8 @@ export const NodeTransforms = { ) } - const [parent, parentPath] = Editor.node(editor, Path.parent(path)) + const parentNodeEntry = Editor.node(editor, Path.parent(path)) + const [parent, parentPath] = parentNodeEntry as NodeEntry const index = path[path.length - 1] const { length } = parent.children @@ -721,7 +724,7 @@ export const NodeTransforms = { for (const pathRef of pathRefs) { const path = pathRef.unref()! - const [node] = Editor.node(editor, path) + const [node] = Editor.node(editor, path) as NodeEntry let range = Editor.range(editor, path) if (split && rangeRef) { @@ -823,7 +826,8 @@ export const NodeTransforms = { : Path.common(firstPath, lastPath) const range = Editor.range(editor, firstPath, lastPath) - const [commonNode] = Editor.node(editor, commonPath) + const commonNodeEntry = Editor.node(editor, commonPath) + const [commonNode] = commonNodeEntry as NodeEntry const depth = commonPath.length + 1 const wrapperPath = Path.next(lastPath.slice(0, depth)) const wrapper = { ...element, children: [] }