diff --git a/src/common/index.ts b/src/common/index.ts index 1f39b430b..75f7fe038 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,6 +1,8 @@ import Backbone from 'backbone'; export { default as $ } from '../utils/cash-dom'; +interface NOOP {} + export type Debounced = Function & { cancel(): void }; export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean }; @@ -17,6 +19,9 @@ export type ObjectAny = Record; export type ObjectStrings = Record; +// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-1483854699 +export type LiteralUnion = T | (U & NOOP); + export type Position = { x: number; y: number; diff --git a/src/editor/index.ts b/src/editor/index.ts index 70d53367d..86af9b199 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -60,7 +60,7 @@ import BlockManager, { BlockEvent } from '../block_manager'; import CanvasModule, { CanvasEvent } from '../canvas'; import CodeManagerModule from '../code_manager'; import CommandsModule, { CommandEvent } from '../commands'; -import { EventHandler } from '../common'; +import { EventHandler, LiteralUnion } from '../common'; import CssComposer from '../css_composer'; import CssRule from '../css_composer/model/CssRule'; import CssRules from '../css_composer/model/CssRules'; @@ -98,7 +98,9 @@ export type ParsedRule = { params?: string; }; -type EditorEvent = +type GeneralEvent = 'canvasScroll' | 'undo' | 'redo' | 'load' | 'update'; + +type EditorBuiltInEvents = | ComponentEvent | BlockEvent | AssetEvent @@ -110,10 +112,9 @@ type EditorEvent = | RichTextEditorEvent | ModalEvent | CommandEvent - | GeneralEvent - | string; + | GeneralEvent; -type GeneralEvent = 'canvasScroll' | 'undo' | 'redo' | 'load' | 'update'; +type EditorEvent = LiteralUnion; type EditorConfigType = EditorConfig & { pStylePrefix?: string };