add AllExtensions interface
This commit is contained in:
@@ -14,7 +14,7 @@ import createStyleTag from './utils/createStyleTag'
|
||||
import CommandManager from './CommandManager'
|
||||
import ExtensionManager from './ExtensionManager'
|
||||
import EventEmitter from './EventEmitter'
|
||||
import { Extensions } from './types'
|
||||
import { Extensions, UnionToIntersection, PickValue } from './types'
|
||||
import defaultPlugins from './plugins'
|
||||
import * as coreCommands from './commands'
|
||||
import style from './style'
|
||||
@@ -35,19 +35,13 @@ export interface CommandsSpec {
|
||||
[key: string]: CommandSpec
|
||||
}
|
||||
|
||||
export interface Commands {}
|
||||
export interface AllExtensions {}
|
||||
|
||||
export type CommandNames = Extract<keyof Commands, string>
|
||||
|
||||
export type SingleCommands = {
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
export type SingleCommands = UnionToIntersection<ReturnType<PickValue<ReturnType<AllExtensions[keyof AllExtensions]>, 'addCommands'>>>
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => ChainedCommands
|
||||
[Item in keyof SingleCommands]: SingleCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<SingleCommands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
|
||||
@@ -27,3 +27,9 @@ export type GlobalAttributes = {
|
||||
types: string[],
|
||||
attributes: Attributes,
|
||||
}[]
|
||||
|
||||
export type PickValue<T, K extends keyof T> = T[K]
|
||||
|
||||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I)=>void)
|
||||
? I
|
||||
: never
|
||||
|
||||
Reference in New Issue
Block a user