refactor: replace a few any-s with proper types (#25681)
This commit is contained in:
parent
603f9242d9
commit
fb11a12d5b
19 changed files with 170 additions and 53 deletions
116
typings/internal-ambient.d.ts
vendored
116
typings/internal-ambient.d.ts
vendored
|
@ -92,6 +92,11 @@ declare namespace NodeJS {
|
|||
initAsarSupport(require: NodeJS.Require): void;
|
||||
}
|
||||
|
||||
interface PowerMonitorBinding extends Electron.PowerMonitor {
|
||||
createPowerMonitor(): PowerMonitorBinding;
|
||||
setListeningForShutdown(listening: boolean): void;
|
||||
}
|
||||
|
||||
type DataPipe = {
|
||||
write: (buf: Uint8Array) => Promise<void>;
|
||||
done: () => void;
|
||||
|
@ -138,16 +143,51 @@ declare namespace NodeJS {
|
|||
}
|
||||
|
||||
interface Process {
|
||||
internalBinding?(name: string): any;
|
||||
_linkedBinding(name: string): any;
|
||||
_linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
|
||||
_linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
|
||||
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
|
||||
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
|
||||
_linkedBinding(name: 'electron_common_asar'): AsarBinding;
|
||||
_linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
|
||||
_linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
|
||||
_linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
|
||||
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
|
||||
_linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
|
||||
_linkedBinding(name: 'electron_common_native_theme'): { nativeTheme: Electron.NativeTheme };
|
||||
_linkedBinding(name: 'electron_common_notification'): {
|
||||
isSupported(): boolean;
|
||||
Notification: typeof Electron.Notification;
|
||||
}
|
||||
_linkedBinding(name: 'electron_common_screen'): { createScreen(): Electron.Screen };
|
||||
_linkedBinding(name: 'electron_common_shell'): Electron.Shell;
|
||||
_linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
|
||||
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
|
||||
_linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
|
||||
_linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
|
||||
_linkedBinding(name: 'electron_browser_crash_reporter'): Omit<Electron.CrashReporter, 'start'> & {
|
||||
start(submitUrl: string,
|
||||
uploadToServer: boolean,
|
||||
ignoreSystemCrashHandler: boolean,
|
||||
rateLimit: boolean,
|
||||
compress: boolean,
|
||||
globalExtra: Record<string, string>,
|
||||
extra: Record<string, string>,
|
||||
isNodeProcess: boolean): void;
|
||||
};
|
||||
_linkedBinding(name: 'electron_browser_desktop_capturer'): {
|
||||
createDesktopCapturer(): ElectronInternal.DesktopCapturer;
|
||||
};
|
||||
_linkedBinding(name: 'electron_browser_event'): {
|
||||
createWithSender(sender: Electron.WebContents): Electron.Event;
|
||||
createEmpty(): Electron.Event;
|
||||
};
|
||||
_linkedBinding(name: 'electron_browser_event_emitter'): {
|
||||
setEventEmitterPrototype(prototype: Object): void;
|
||||
};
|
||||
_linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
|
||||
_linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
|
||||
_linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
|
||||
_linkedBinding(name: 'electron_browser_message_port'): {
|
||||
createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain };
|
||||
};
|
||||
_linkedBinding(name: 'electron_browser_net'): {
|
||||
isValidHeaderName: (headerName: string) => boolean;
|
||||
isValidHeaderValue: (headerValue: string) => boolean;
|
||||
|
@ -155,7 +195,15 @@ declare namespace NodeJS {
|
|||
net: any;
|
||||
createURLLoader(options: CreateURLLoaderOptions): URLLoader;
|
||||
};
|
||||
_linkedBinding(name: 'electron_common_asar'): AsarBinding;
|
||||
_linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
|
||||
_linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
|
||||
_linkedBinding(name: 'electron_browser_session'): typeof Electron.Session;
|
||||
_linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
|
||||
_linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
|
||||
_linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
|
||||
_linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
|
||||
_linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
|
||||
_linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
|
||||
log: NodeJS.WriteStream['write'];
|
||||
activateUvLoop(): void;
|
||||
|
||||
|
@ -259,3 +307,61 @@ interface ResizeObserverEntry {
|
|||
*/
|
||||
readonly contentRect: DOMRectReadOnly;
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/pull/38232
|
||||
|
||||
interface WeakRef<T extends object> {
|
||||
readonly [Symbol.toStringTag]: "WeakRef";
|
||||
|
||||
/**
|
||||
* Returns the WeakRef instance's target object, or undefined if the target object has been
|
||||
* reclaimed.
|
||||
*/
|
||||
deref(): T | undefined;
|
||||
}
|
||||
|
||||
interface WeakRefConstructor {
|
||||
readonly prototype: WeakRef<any>;
|
||||
|
||||
/**
|
||||
* Creates a WeakRef instance for the given target object.
|
||||
* @param target The target object for the WeakRef instance.
|
||||
*/
|
||||
new<T extends object>(target?: T): WeakRef<T>;
|
||||
}
|
||||
|
||||
declare var WeakRef: WeakRefConstructor;
|
||||
|
||||
interface FinalizationRegistry {
|
||||
readonly [Symbol.toStringTag]: "FinalizationRegistry";
|
||||
|
||||
/**
|
||||
* Registers an object with the registry.
|
||||
* @param target The target object to register.
|
||||
* @param heldValue The value to pass to the finalizer for this object. This cannot be the
|
||||
* target object.
|
||||
* @param unregisterToken The token to pass to the unregister method to unregister the target
|
||||
* object. If provided (and not undefined), this must be an object. If not provided, the target
|
||||
* cannot be unregistered.
|
||||
*/
|
||||
register(target: object, heldValue: any, unregisterToken?: object): void;
|
||||
|
||||
/**
|
||||
* Unregisters an object from the registry.
|
||||
* @param unregisterToken The token that was used as the unregisterToken argument when calling
|
||||
* register to register the target object.
|
||||
*/
|
||||
unregister(unregisterToken: object): void;
|
||||
}
|
||||
|
||||
interface FinalizationRegistryConstructor {
|
||||
readonly prototype: FinalizationRegistry;
|
||||
|
||||
/**
|
||||
* Creates a finalization registry with an associated cleanup callback
|
||||
* @param cleanupCallback The callback to call after an object in the registry has been reclaimed.
|
||||
*/
|
||||
new(cleanupCallback: (heldValue: any) => void): FinalizationRegistry;
|
||||
}
|
||||
|
||||
declare var FinalizationRegistry: FinalizationRegistryConstructor;
|
||||
|
|
21
typings/internal-electron.d.ts
vendored
21
typings/internal-electron.d.ts
vendored
|
@ -21,7 +21,12 @@ declare namespace Electron {
|
|||
|
||||
type TouchBarItemType = NonNullable<Electron.TouchBarConstructorOptions['items']>[0];
|
||||
|
||||
interface BaseWindow {
|
||||
_init(): void;
|
||||
}
|
||||
|
||||
interface BrowserWindow {
|
||||
_init(): void;
|
||||
_touchBar: Electron.TouchBar | null;
|
||||
_setTouchBarItems: (items: TouchBarItemType[]) => void;
|
||||
_setEscapeTouchBarItem: (item: TouchBarItemType | {}) => void;
|
||||
|
@ -47,7 +52,7 @@ declare namespace Electron {
|
|||
|
||||
interface WebContents {
|
||||
_getURL(): string;
|
||||
_loadURL(url: string, options: Electron.LoadURLOptions): void;
|
||||
_loadURL(url: string, options: ElectronInternal.LoadURLOptions): void;
|
||||
_stop(): void;
|
||||
_goBack(): void;
|
||||
_goForward(): void;
|
||||
|
@ -61,7 +66,7 @@ declare namespace Electron {
|
|||
browserWindowOptions: BrowserWindowConstructorOptions;
|
||||
_send(internal: boolean, sendToAll: boolean, channel: string, args: any): boolean;
|
||||
_sendToFrame(internal: boolean, sendToAll: boolean, frameId: number, channel: string, args: any): boolean;
|
||||
_sendToFrameInternal(frameId: number, channel: string, args: any): boolean;
|
||||
_sendToFrameInternal(frameId: number, channel: string, ...args: any[]): boolean;
|
||||
_postMessage(channel: string, message: any, transfer?: any[]): void;
|
||||
_sendInternal(channel: string, ...args: any[]): void;
|
||||
_sendInternalToAll(channel: string, ...args: any[]): void;
|
||||
|
@ -123,6 +128,10 @@ declare namespace Electron {
|
|||
acceleratorWorksWhenHidden?: boolean;
|
||||
}
|
||||
|
||||
interface IpcMainInvokeEvent {
|
||||
_reply(value: any): void;
|
||||
_throw(error: Error): void;
|
||||
}
|
||||
|
||||
const deprecate: ElectronInternal.DeprecationUtil;
|
||||
|
||||
|
@ -177,8 +186,8 @@ declare namespace ElectronInternal {
|
|||
getHandler(): DeprecationHandler | null;
|
||||
warn(oldName: string, newName: string): void;
|
||||
log(message: string): void;
|
||||
removeFunction(fn: Function, removedName: string): Function;
|
||||
renameFunction(fn: Function, newName: string | Function): Function;
|
||||
removeFunction<T extends Function>(fn: T, removedName: string): T;
|
||||
renameFunction<T extends Function>(fn: T, newName: string): T;
|
||||
event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
|
||||
removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K, onlyForValues?: any[]): T;
|
||||
renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
|
||||
|
@ -222,6 +231,10 @@ declare namespace ElectronInternal {
|
|||
once(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
|
||||
}
|
||||
|
||||
interface LoadURLOptions extends Electron.LoadURLOptions {
|
||||
reloadIgnoringCache?: boolean;
|
||||
}
|
||||
|
||||
type ModuleLoader = () => any;
|
||||
|
||||
interface ModuleEntry {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue