Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use "as const" for constant mappings #28980

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/browser/api/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { app, BrowserWindow } from 'electron/main';
import type { OpenDialogOptions, OpenDialogReturnValue, MessageBoxOptions, SaveDialogOptions, SaveDialogReturnValue, MessageBoxReturnValue, CertificateTrustDialogOptions } from 'electron/main';
const dialogBinding = process._linkedBinding('electron_browser_dialog');

const DialogType = {
OPEN: 'OPEN' as 'OPEN',
SAVE: 'SAVE' as 'SAVE'
};
enum DialogType {
OPEN = 'OPEN',
SAVE = 'SAVE'
}

enum SaveFileDialogProperties {
createDirectory = 1 << 0,
Expand Down Expand Up @@ -72,7 +72,7 @@ const setupSaveDialogProperties = (properties: (keyof typeof SaveFileDialogPrope
return dialogProperties;
};

const setupDialogProperties = (type: keyof typeof DialogType, properties: string[]): number => {
const setupDialogProperties = (type: DialogType, properties: string[]): number => {
if (type === DialogType.OPEN) {
return setupOpenDialogProperties(properties as (keyof typeof OpenFileDialogProperties)[]);
} else if (type === DialogType.SAVE) {
Expand Down
6 changes: 3 additions & 3 deletions lib/browser/api/web-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const PDFPageSizes: Record<string, ElectronInternal.MediaSize> = {
width_microns: 279400,
custom_display_name: 'Tabloid'
}
};
} as const;

// The minimum micron size Chromium accepts is that where:
// Per printing/units.h:
Expand Down Expand Up @@ -109,7 +109,7 @@ const defaultPrintingSetting = {
printerType: 2,
title: undefined as string | undefined,
url: undefined as string | undefined
};
} as const;

// JavaScript implementations of WebContents.
const binding = process._linkedBinding('electron_browser_web_contents');
Expand Down Expand Up @@ -191,7 +191,7 @@ WebContents.prototype.executeJavaScriptInIsolatedWorld = async function (worldId

let pendingPromise: Promise<any> | undefined;
WebContents.prototype.printToPDF = async function (options) {
const printSettings = {
const printSettings: Record<string, any> = {
...defaultPrintingSetting,
requestID: getNextId()
};
Expand Down
4 changes: 2 additions & 2 deletions lib/common/web-view-events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const webViewEvents: Record<string, string[]> = {
export const webViewEvents: Record<string, readonly string[]> = {
'load-commit': ['url', 'isMainFrame'],
'did-attach': [],
'did-finish-load': [],
Expand Down Expand Up @@ -33,4 +33,4 @@ export const webViewEvents: Record<string, string[]> = {
'found-in-page': ['result'],
'did-change-theme-color': ['themeColor'],
'update-target-url': ['url']
};
} as const;
2 changes: 1 addition & 1 deletion lib/renderer/web-view/guest-view-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';

const DEPRECATED_EVENTS: Record<string, string> = {
'page-title-updated': 'page-title-set'
};
} as const;

const dispatchEvent = function (
webView: WebViewImpl, eventName: string, eventKey: string, ...args: Array<any>
Expand Down