Skip to content

Commit

Permalink
chore: API types
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnuqw committed Mar 4, 2024
1 parent 66bef45 commit 64e7323
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/types/web-ext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ declare namespace browser {
name: string
disconnect: () => void
error?: Error
onDisconnect: EventTarget<DisconnectListener>
onMessage: EventTarget<PortMessageListener>
onDisconnect: PortEventTarget
onMessage: PortEventTarget
postMessage: <T>(msg: T) => void
sender?: Sender
}

interface EventTarget<T> {
interface PortEventTarget {
addListener: <T>(listener: T) => void
removeListener: <T>(listener: T) => void
}
Expand Down Expand Up @@ -88,6 +88,10 @@ declare namespace browser {
buildID: string
}

interface UpdateDetails {
version: string
}

function sendMessage<T, R>(msg: T): Promise<R>
function getURL(resource: string): string
function openOptionsPage(): void
Expand All @@ -99,9 +103,11 @@ declare namespace browser {

type MessageListener = <I, O>(msg: I) => Promise<O>
type ConnectListener = (port: Port) => void
type UpdateAvailableListener = (details: UpdateDetails) => void

const onMessage: EventTarget<MessageListener>
const onConnect: EventTarget<ConnectListener>
const onMessage: PortEventTarget
const onConnect: PortEventTarget
const onUpdateAvailable: EventTarget<UpdateAvailableListener>
}

/**
Expand Down

0 comments on commit 64e7323

Please sign in to comment.