From 81d2f9bb8f6a78590d7868deb289ec36fb208629 Mon Sep 17 00:00:00 2001 From: CameronAckermanSEL Date: Mon, 4 May 2020 17:33:39 -0700 Subject: [PATCH] Revert "TypeScript Improvement: Use `[key: string]: unknown`, not `[key: string]: any` (#3565)" This reverts commit d8adf51add861c81b51e969de704d93a51a8990f. --- docs/api/locations.md | 4 ++-- docs/api/nodes.md | 6 ++--- docs/concepts/01-interfaces.md | 4 ++-- docs/concepts/02-nodes.md | 4 ++-- docs/concepts/03-locations.md | 4 ++-- docs/concepts/06-editor.md | 2 +- .../slate-react/src/components/editable.tsx | 4 ++-- packages/slate-react/src/components/leaf.tsx | 2 +- packages/slate-react/src/components/slate.tsx | 2 +- packages/slate/src/interfaces/editor.ts | 4 ++-- packages/slate/src/interfaces/element.ts | 2 +- packages/slate/src/interfaces/operation.ts | 22 +++++++++---------- packages/slate/src/interfaces/point.ts | 2 +- packages/slate/src/interfaces/range.ts | 2 +- packages/slate/src/interfaces/text.ts | 2 +- packages/slate/src/transforms/general.ts | 4 ++-- packages/slate/src/transforms/node.ts | 10 +++------ 17 files changed, 38 insertions(+), 42 deletions(-) diff --git a/docs/api/locations.md b/docs/api/locations.md index 275374596..3325ef6d4 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]: unknown + [key: string]: any } ``` @@ -68,7 +68,7 @@ Options: `{affinity?: 'forward' | 'backward' | null}` interface Range { anchor: Point focus: Point - [key: string]: unknown + [key: string]: any } ``` diff --git a/docs/api/nodes.md b/docs/api/nodes.md index b18321f9b..6fea366d6 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]: unknown + [key: string]: any // 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]: unknown + [key: string]: any } ``` @@ -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]: unknown + [key: string]: any } ``` diff --git a/docs/concepts/01-interfaces.md b/docs/concepts/01-interfaces.md index 74f40a69b..e77443cfc 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]: unknown + [key: string]: any } ``` @@ -22,7 +22,7 @@ To take another example, the `Element` node interface in Slate is: ```ts interface Element { children: Node[] - [key: string]: unknown + [key: string]: any } ``` diff --git a/docs/concepts/02-nodes.md b/docs/concepts/02-nodes.md index 6454bbd1a..a43f36ab9 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]: unknown + [key: string]: any } ``` @@ -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]: unknown + [key: string]: any } ``` diff --git a/docs/concepts/03-locations.md b/docs/concepts/03-locations.md index f9b9f49fa..795a121ed 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]: unknown + [key: string]: any } ``` @@ -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]: unknown + [key: string]: any } ``` diff --git a/docs/concepts/06-editor.md b/docs/concepts/06-editor.md index 20e2e22bb..2657c2674 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]: unknown + [key: string]: any // 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 73b3452e4..44fcc60ae 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 (typeof editor.redo === 'function') { + if (editor.redo) { editor.redo() } @@ -718,7 +718,7 @@ export const Editable = (props: EditableProps) => { if (Hotkeys.isUndo(nativeEvent)) { event.preventDefault() - if (typeof editor.undo === 'function') { + if (editor.undo) { editor.undo() } diff --git a/packages/slate-react/src/components/leaf.tsx b/packages/slate-react/src/components/leaf.tsx index 0d3e438a4..8ab9fcd25 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 as React.ReactNode} + {leaf.placeholder} {children} diff --git a/packages/slate-react/src/components/slate.tsx b/packages/slate-react/src/components/slate.tsx index 82b3caa0c..49d5307b4 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]: unknown + [key: string]: any }) => { 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 5e48a5ff1..782c36aed 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]: unknown + [key: string]: any // 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)) as Ancestor + const newParent = Node.get(editor, Path.parent(truePath)) 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 34361e8c2..b63c9b428 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]: unknown + [key: string]: any } export const Element = { diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index c9cc22088..e8791fcd4 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]: unknown + [key: string]: any } export type InsertTextOperation = { @@ -13,7 +13,7 @@ export type InsertTextOperation = { path: Path offset: number text: string - [key: string]: unknown + [key: string]: any } export type MergeNodeOperation = { @@ -22,21 +22,21 @@ export type MergeNodeOperation = { position: number target: number | null properties: Partial - [key: string]: unknown + [key: string]: any } export type MoveNodeOperation = { type: 'move_node' path: Path newPath: Path - [key: string]: unknown + [key: string]: any } export type RemoveNodeOperation = { type: 'remove_node' path: Path node: Node - [key: string]: unknown + [key: string]: any } export type RemoveTextOperation = { @@ -44,7 +44,7 @@ export type RemoveTextOperation = { path: Path offset: number text: string - [key: string]: unknown + [key: string]: any } export type SetNodeOperation = { @@ -52,25 +52,25 @@ export type SetNodeOperation = { path: Path properties: Partial newProperties: Partial - [key: string]: unknown + [key: string]: any } export type SetSelectionOperation = | { type: 'set_selection' - [key: string]: unknown + [key: string]: any properties: null newProperties: Range } | { type: 'set_selection' - [key: string]: unknown + [key: string]: any properties: Partial newProperties: Partial } | { type: 'set_selection' - [key: string]: unknown + [key: string]: any properties: Range newProperties: null } @@ -81,7 +81,7 @@ export type SplitNodeOperation = { position: number target: number | null properties: Partial - [key: string]: unknown + [key: string]: any } export type NodeOperation = diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index 971b6486c..20fce6759 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]: unknown + [key: string]: any } export const Point = { diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 5f53bfcd8..e2d60c681 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]: unknown + [key: string]: any } export const Range = { diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts index 96eb750c4..80ca65f22 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]: unknown + [key: string]: any } export const Text = { diff --git a/packages/slate/src/transforms/general.ts b/packages/slate/src/transforms/general.ts index 5b170dfd4..cd6e7da00 100755 --- a/packages/slate/src/transforms/general.ts +++ b/packages/slate/src/transforms/general.ts @@ -10,7 +10,7 @@ import { Descendant, NodeEntry, Path, - Ancestor, + Transforms, } 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)) as Ancestor + const newParent = Node.get(editor, Path.parent(truePath)) 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 ec07de9c0..03d1e4f3f 100644 --- a/packages/slate/src/transforms/node.ts +++ b/packages/slate/src/transforms/node.ts @@ -8,8 +8,6 @@ import { Range, Text, Transforms, - NodeEntry, - Ancestor, } from '..' export const NodeTransforms = { @@ -170,8 +168,7 @@ export const NodeTransforms = { ) } - const parentNodeEntry = Editor.node(editor, Path.parent(path)) - const [parent, parentPath] = parentNodeEntry as NodeEntry + const [parent, parentPath] = Editor.node(editor, Path.parent(path)) const index = path[path.length - 1] const { length } = parent.children @@ -724,7 +721,7 @@ export const NodeTransforms = { for (const pathRef of pathRefs) { const path = pathRef.unref()! - const [node] = Editor.node(editor, path) as NodeEntry + const [node] = Editor.node(editor, path) let range = Editor.range(editor, path) if (split && rangeRef) { @@ -826,8 +823,7 @@ export const NodeTransforms = { : Path.common(firstPath, lastPath) const range = Editor.range(editor, firstPath, lastPath) - const commonNodeEntry = Editor.node(editor, commonPath) - const [commonNode] = commonNodeEntry as NodeEntry + const [commonNode] = Editor.node(editor, commonPath) const depth = commonPath.length + 1 const wrapperPath = Path.next(lastPath.slice(0, depth)) const wrapper = { ...element, children: [] }