diff --git a/types/slate-react/index.d.ts b/types/slate-react/index.d.ts index 2e04b32168..10bf3fcfdb 100644 --- a/types/slate-react/index.d.ts +++ b/types/slate-react/index.d.ts @@ -114,12 +114,18 @@ export interface Plugin extends CorePlugin { export type PluginOrPlugins = Plugin | Plugins; export interface Plugins extends Array {} +export interface OnChangeParam { + operations: Immutable.List; + value: Value; +} +export type OnChangeFn = (change: OnChangeParam) => any; + export interface BasicEditorProps { value: Value; autoCorrect?: boolean; autoFocus?: boolean; className?: string; - onChange?: (change: { operations: Immutable.List; value: Value }) => any; + onChange?: OnChangeFn; placeholder?: any; plugins?: Plugins; readOnly?: boolean; diff --git a/types/slate-react/slate-react-tests.tsx b/types/slate-react/slate-react-tests.tsx index f49a6ffefa..b236728ce2 100644 --- a/types/slate-react/slate-react-tests.tsx +++ b/types/slate-react/slate-react-tests.tsx @@ -1,15 +1,14 @@ -import { Editor, Plugin, EditorProps, RenderBlockProps, RenderInlineProps } from "slate-react"; -import { Value, Editor as Controller, Operation, Point, Range, Inline, Mark, Document, Decoration } from "slate"; +import { Editor, Plugin, EditorProps, OnChangeFn, RenderBlockProps, RenderInlineProps } from 'slate-react'; +import { Value, Editor as Controller, Point, Range, Inline, Mark, Document, Decoration } from 'slate'; import * as React from "react"; -import * as Immutable from "immutable"; class MyPlugin implements Plugin { renderBlock(props: RenderBlockProps, editor: Controller, next: () => void) { const { node } = props; if (node) { switch (node.object) { - case "block": - return
; + case 'block': + return
; default: return undefined; } @@ -19,15 +18,15 @@ class MyPlugin implements Plugin { const { node } = props; if (node) { switch (node.object) { - case "inline": + case 'inline': return Hello world; default: return undefined; } } } - onChange = (change: {operations: Immutable.List, value: Value}) => { - console.log(change.value); + onChange: OnChangeFn = ({ operations, value }) => { + console.log(operations, value); } }