diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index c242e497..dfa947dc 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -23,7 +23,8 @@ import { CanCommands, ChainedCommands, SingleCommands, - TextSerializer, EditorEvents, + TextSerializer, + EditorEvents, } from './types' import * as extensions from './extensions' import style from './style' diff --git a/packages/core/src/EventEmitter.ts b/packages/core/src/EventEmitter.ts index 68777c93..56ba9886 100644 --- a/packages/core/src/EventEmitter.ts +++ b/packages/core/src/EventEmitter.ts @@ -1,12 +1,18 @@ -type StringKeyOf = Extract; -type CallbackType, EVENT extends StringKeyOf> = T[EVENT] extends any[] ? T[EVENT] : [T[EVENT]]; -type CallbackFunction, EVENT extends StringKeyOf> = (...props: CallbackType) => any +type StringKeyOf = Extract +type CallbackType< + T extends Record, + EventName extends StringKeyOf, +> = T[EventName] extends any[] ? T[EventName] : [T[EventName]] +type CallbackFunction< + T extends Record, + EventName extends StringKeyOf, +> = (...props: CallbackType) => any export default class EventEmitter> { private callbacks: { [key: string]: Function[] } = {} - public on>(event: EVENT, fn: CallbackFunction): this { + public on>(event: EventName, fn: CallbackFunction): this { if (!this.callbacks[event]) { this.callbacks[event] = [] } @@ -16,7 +22,7 @@ export default class EventEmitter> { return this } - protected emit>(event: EVENT, ...args: CallbackType): this { + protected emit>(event: EventName, ...args: CallbackType): this { const callbacks = this.callbacks[event] if (callbacks) { @@ -26,7 +32,7 @@ export default class EventEmitter> { return this } - public off>(event: EVENT, fn?: CallbackFunction): this { + public off>(event: EventName, fn?: CallbackFunction): this { const callbacks = this.callbacks[event] if (callbacks) { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 454639f7..712528b1 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -140,9 +140,9 @@ export type UnionToIntersection = (U extends any ? (k: U) => void : never) ex export type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T] -export type Overwrite = Pick> & U; +export type Overwrite = Pick> & U -export type ValuesOf = T[keyof T]; +export type ValuesOf = T[keyof T] export type KeysWithTypeOf = ({ [P in keyof T]: T[P] extends Type ? P : never })[keyof T]