Last active
January 13, 2023 03:05
-
-
Save mstoecklein/6f0787c663101f78367586d675dd2088 to your computer and use it in GitHub Desktop.
Polyfill type declaration to use service worker types in a deno environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Polyfill type declaration to use service worker types in a deno environment | |
interface FetchEvent extends Event { | |
request: Request; | |
respondWith(response: Promise<Response> | Response): void; | |
} | |
interface GlobalEventHandlersEventMap { | |
fetch: FetchEvent; | |
} | |
interface BatteryManagerEventMap { | |
chargingchange: Event; | |
chargingtimechange: Event; | |
dischargingtimechange: Event; | |
levelchange: Event; | |
} | |
interface BatteryManager { | |
level: number; | |
charging: boolean; | |
addEventListener<K extends keyof BatteryManagerEventMap>( | |
type: K, | |
// deno-lint-ignore no-explicit-any | |
listener: (this: this, ev: BatteryManagerEventMap[K]) => any, | |
options?: boolean | AddEventListenerOptions, | |
): void; | |
removeEventListener<K extends keyof BatteryManagerEventMap>( | |
type: K, | |
// deno-lint-ignore no-explicit-any | |
listener: (this: this, ev: BatteryManagerEventMap[K]) => any, | |
options?: boolean | EventListenerOptions, | |
): void; | |
} | |
interface NetworkInformationEventMap { | |
change: Event; | |
} | |
interface NetworkInformation extends EventTarget { | |
type: string; | |
downlink: number; | |
downlinkMax: number; | |
effectiveType: string; | |
rtt: number; | |
saveData: boolean; | |
addEventListener<K extends keyof NetworkInformationEventMap>( | |
type: K, | |
// deno-lint-ignore no-explicit-any | |
listener: (this: this, ev: NetworkInformationEventMap[K]) => any, | |
options?: boolean | AddEventListenerOptions, | |
): void; | |
removeEventListener<K extends keyof NetworkInformationEventMap>( | |
type: K, | |
// deno-lint-ignore no-explicit-any | |
listener: (this: this, ev: NetworkInformationEventMap[K]) => any, | |
options?: boolean | EventListenerOptions, | |
): void; | |
} | |
interface Navigator { | |
getBattery: () => Promise<BatteryManager>; | |
connection: NetworkInformation; | |
onLine: boolean; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment