Skip to content

Commit

Permalink
fix: some d.ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jul 16, 2024
1 parent 447d363 commit b00f667
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
53 changes: 39 additions & 14 deletions eruda.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ declare module 'eruda' {
y: number
}

export interface Emitter {}
type AnyFn = (...args: any[]) => any

export interface Emitter {
on(event: string, listener: AnyFn): Emitter
off(event: string, listener: AnyFn): Emitter
once(event: string, listener: AnyFn): Emitter
emit(event: string, ...args: any[]): Emitter
removeAllListeners(event?: string): Emitter
}

/**
* Eruda Plugin
Expand Down Expand Up @@ -165,11 +173,16 @@ declare module 'eruda' {
}

export interface Elements extends Tool {
set<K extends keyof ElementsConfig>(name: K, value: ElementsConfig[K]): void
config: {
set<K extends keyof ElementsConfig>(
name: K,
value: ElementsConfig[K]
): void
}
/**
* Element to display
*/
html(el: HTMLElement): void
select(el: HTMLElement): void
}

export interface ElementsConstructor {
Expand Down Expand Up @@ -205,10 +218,12 @@ declare module 'eruda' {
}

export interface Resources extends Tool {
set<K extends keyof ResourcesConfig>(
name: K,
value: ResourcesConfig[K]
): void
config: {
set<K extends keyof ResourcesConfig>(
name: K,
value: ResourcesConfig[K]
): void
}
}

export interface ResourcesConstructor {
Expand All @@ -232,7 +247,9 @@ declare module 'eruda' {
}

export interface Sources extends Tool {
set<K extends keyof SourcesConfig>(name: K, value: SourcesConfig[K]): void
config: {
set<K extends keyof SourcesConfig>(name: K, value: SourcesConfig[K]): void
}
}

export interface SourcesConstructor {
Expand Down Expand Up @@ -402,6 +419,18 @@ declare module 'eruda' {
getTheme(): string
}

interface IToolNameMap {
console: InstanceType<ErudaConsoleConstructor>
elements: InstanceType<ElementsConstructor>
info: InstanceType<InfoConstructor>
network: InstanceType<NetworkConstructor>
resources: InstanceType<ResourcesConstructor>
settings: InstanceType<SettingsConstructor>
snippets: InstanceType<SnippetsConstructor>
sources: InstanceType<SourcesConstructor>
entryBtn: InstanceType<EntryBtnConstructor>
}

/**
* Eruda APIs
* @see https://eruda.liriliri.io/docs/api.html
Expand Down Expand Up @@ -430,13 +459,9 @@ declare module 'eruda' {
/**
* Get tool, eg. console, elements panels.
*/
get<K extends keyof IToolNameMap>(name: K): IToolNameMap[K]
get<T extends ToolConstructor>(name: string): InstanceType<T> | undefined
get(
name: string
):
| InstanceType<EntryBtnConstructor>
| InstanceType<DevToolsConstructor>
| undefined
get(): InstanceType<DevToolsConstructor>
/**
* Add tool.
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Elements/Elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ export default class Elements extends Tool {

chobitsu.domain('Overlay').hideHighlight()
}
// To be removed in 3.0.0
set(node) {
return this.select(node)
}
select(node) {
this._domViewer.select(node)
this._setNode(node)
Expand Down

0 comments on commit b00f667

Please sign in to comment.