forked from YaoApp/xgen-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typings.d.ts
50 lines (45 loc) · 1.75 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
declare module '*.png'
declare module '*.jpg'
declare module '*.jpeg'
declare module '*.svg' {
export function ReactComponent(props: React.SVGProps<SVGSVGElement>): React.ReactElement
const url: string
export default url
}
declare module 'less-vars-to-js'
declare module '@lcdp/offline-plugin'
declare module 'dva-model-extend' {
import type { Model } from 'R/src/typings/dva'
const modelExtend: (common_model: Model, target_model: Model) => Model
export default modelExtend
}
interface Window {
OSS: any
$app: {
memo: <T>(
el: (props: T) => JSX.Element | null
) => React.MemoExoticComponent<(props: T) => JSX.Element | null>
nextTick: () => Promise<unknown>
sleep: (time: number) => Promise<unknown>
emitter: Emitter<Record<EventType, unknown>>
oss: any
}
}
type EventType = string | symbol
type Handler<T = unknown> = (event: T) => void
type WildcardHandler<T = Record<string, unknown>> = (type: keyof T, event: T[keyof T]) => void
type EventHandlerList<T = unknown> = Array<Handler<T>>
type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>
type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
keyof Events | '*',
EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>
>
interface Emitter<Events extends Record<EventType, unknown>> {
all: EventHandlerMap<Events>
on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void
on(type: '*', handler: WildcardHandler<Events>): void
off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void
off(type: '*', handler: WildcardHandler<Events>): void
emit<Key extends keyof Events>(type: Key, event: Events[Key]): void
emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void
}