From ceeb34436fa378a2aa4453e94a510bfc1f600b14 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 12 Mar 2022 18:18:17 -0600 Subject: [PATCH] monaco-extension: add types for internal methods --- src/editor/Editor.tsx | 2 -- src/monaco-extension.d.ts | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/monaco-extension.d.ts diff --git a/src/editor/Editor.tsx b/src/editor/Editor.tsx index 89e57f3f..975fc6f9 100644 --- a/src/editor/Editor.tsx +++ b/src/editor/Editor.tsx @@ -127,7 +127,6 @@ const contextMenu = (_props: ContextMenu2ContentProps): JSX.Element => { text={i18n.translate(EditorStringId.Undo)} icon="undo" label={isMacOS() ? 'Cmd-Z' : 'Ctrl-Z'} - // @ts-expect-error internal method canUndo() disabled={!editor?.getModel()?.canUndo()} /> { text={i18n.translate(EditorStringId.Redo)} icon="redo" label={isMacOS() ? 'Cmd-Shift-Z' : 'Ctrl-Shift-Z'} - // @ts-expect-error internal method canUndo() disabled={!editor?.getModel()?.canRedo()} /> diff --git a/src/monaco-extension.d.ts b/src/monaco-extension.d.ts new file mode 100644 index 00000000..e8520fd0 --- /dev/null +++ b/src/monaco-extension.d.ts @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2022 The Pybricks Authors + +// exposes some monaco editor internal functions + +import {} from 'react-monaco-editor'; + +declare module 'react-monaco-editor' { + export namespace monaco { + export namespace editor { + export interface ITextModel { + // https://github.com/microsoft/vscode/blob/d54c705f6567958a732ac88b1c3ec4d2303fb026/src/vs/editor/common/model.ts#L1135 + canUndo: () => boolean; + // https://github.com/microsoft/vscode/blob/d54c705f6567958a732ac88b1c3ec4d2303fb026/src/vs/editor/common/model.ts#L1148 + canRedo: () => boolean; + } + } + } +}