Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6052b0b
Convert type any to type unknown
martgil Jun 24, 2022
9fb990d
remove console.log()
martgil Jun 24, 2022
a7ae92d
further convert type any to unknown
martgil Jun 27, 2022
0913777
further convert type any to unknown
martgil Jun 27, 2022
25f0bb8
Merge branch 'issue-4490-convert-type-any-to-type-unknown' of https:/…
martgil Jun 27, 2022
0fcc4ad
Revert "further convert type any to unknown"
martgil Jun 27, 2022
fd67623
add node-forge in global scope
martgil Jun 27, 2022
5472b04
Merge branch 'master' of https://github.com/FlowCrypt/flowcrypt-brows…
martgil Jul 4, 2022
4a64afd
Merge branch 'master' into issue-4490-convert-type-any-to-type-unknown
ioanmo226 Jul 5, 2022
74c890d
add types for standalone javascript libs
martgil Jul 12, 2022
bfd98b3
convert any to unknown
martgil Jul 12, 2022
43bea67
Merge remote-tracking branch 'origin/master' into issue-4490-convert-…
martgil Jul 12, 2022
40dbc26
convert any to unknown
martgil Jul 12, 2022
1cbdd09
convert type any to unknown
martgil Jul 13, 2022
12c7033
revert require.ts
martgil Jul 13, 2022
5ede9d5
convert type any to unknown
martgil Jul 13, 2022
ad4a379
Merge remote-tracking branch 'origin/master' into issue-4490-convert-…
martgil Jul 14, 2022
4ed4510
remove tslint comment
martgil Jul 14, 2022
83d49e2
convert type any to unknown
martgil Jul 14, 2022
ebc131d
convert type any to unknown
martgil Jul 14, 2022
71fc9da
revert changes
martgil Jul 14, 2022
e3b08fd
convert type any to unknown
martgil Jul 14, 2022
4a5496f
revert changes from ci_unit_test
martgil Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/chrome/dev/ci_unit_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Gmail } from '../../js/common/api/email-provider/gmail/gmail.js';
* importing all libs that are tested in ci tests
* add lib name below, let the IDE resolve the actual import
*/
const libs: any[] = [
const libs: unknown[] = [
ApiErr,
Attachment,
AttachmentUI,
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/elements/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class AttachmentDownloadView extends View {
}
};

protected renderErr = (e: any) => {
protected renderErr = (e: unknown) => {
if (ApiErr.isAuthErr(e)) {
BrowserMsg.send.notificationShowAuthPopupNeeded(this.parentTabId, { acctEmail: this.acctEmail });
Xss.sanitizeRender('body', `Error downloading file - google auth needed. ${Ui.retryLink()}`);
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/elements/attachment_preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Url } from '../../js/common/core/common.js';

type AttachmentType = 'img' | 'txt' | 'pdf';

declare const pdfjsLib: any; // tslint:disable-line:ban-types
declare const pdfjsLib: { getDocument: Function }; // tslint:disable-line:ban-types

View.run(class AttachmentPreviewView extends AttachmentDownloadView {
protected readonly initiatorFrameId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ComposeErrModule extends ViewModule<ComposeView> {
return {
network: async () => await Ui.modal.info(`Could not ${couldNotDoWhat} (network error). Please try again.`),
auth: async () => Settings.offerToLoginWithPopupShowModalOnErr(this.view.acctEmail, undefined, `Could not ${couldNotDoWhat}.\n`),
other: async (e: any) => {
other: async (e: unknown) => {
if (e instanceof Error) {
e.stack = (e.stack || '') + `\n\n[compose action: ${couldNotDoWhat}]`;
} else if (typeof e === 'object' && e && typeof (e as any).stack === 'undefined') {
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ComposeErrModule extends ViewModule<ComposeView> {
}
};

public handleSendErr = async (e: any, sendMsgsResult?: SendMsgsResult) => {
public handleSendErr = async (e: unknown, sendMsgsResult?: SendMsgsResult) => {
this.view.errModule.debug(`handleSendErr: ${String(e)}`);
if (ApiErr.isNetErr(e)) {
let netErrMsg: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ComposeSendBtnModule extends ViewModule<ComposeView> {
if (result.supplementaryOperationsErrors.length) {
console.error(result.supplementaryOperationsErrors);
Catch.setHandledTimeout(() => {
Ui.toast(result.supplementaryOperationsErrors[0]); // tslint:disable-line:no-unsafe-any
Ui.toast(result.supplementaryOperationsErrors[0] as string);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as X is not so safe, it would be safer to test for what type it is and treat it appropriately

}, 0);
}
BrowserMsg.send.notificationShow(this.view.parentTabId, { notification: `Your ${this.view.isReplyBox ? 'reply' : 'message'} has been sent.` });
Expand Down Expand Up @@ -231,7 +231,7 @@ export class ComposeSendBtnModule extends ViewModule<ComposeView> {
}
};

private bindMessageId = async (externalId: string, id: string, supplementaryOperationsErrors: any[]) => {
private bindMessageId = async (externalId: string, id: string, supplementaryOperationsErrors: unknown[]) => {
try {
const gmailMsg = await this.view.emailProvider.msgGet(id, 'metadata');
const messageId = GmailParser.findHeader(gmailMsg, 'message-id');
Expand All @@ -249,9 +249,9 @@ export class ComposeSendBtnModule extends ViewModule<ComposeView> {
private doSendMsgs = async (msgObj: MultipleMessages): Promise<SendMsgsResult> => {
const sentIds: string[] = [];
const supplementaryOperations: Promise<void>[] = [];
const supplementaryOperationsErrors: any[] = []; // tslint:disable-line:no-unsafe-any
const supplementaryOperationsErrors: unknown[] = [];
const success: EmailParts[] = [];
const failures: { recipient: EmailParts, e: any }[] = [];
const failures: { recipient: EmailParts, e: unknown }[] = [];
for (const msg of msgObj.msgs) {
const msgRecipients = msg.getAllRecipients();
try {
Expand Down
4 changes: 2 additions & 2 deletions extension/chrome/elements/compose-modules/compose-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const getUniqueRecipientEmails = (recipients: ParsedRecipients) => {

export type SendMsgsResult = {
success: EmailParts[],
failures: { recipient: EmailParts, e: any }[],
supplementaryOperationsErrors: any[],
failures: { recipient: EmailParts, e: unknown }[],
supplementaryOperationsErrors: unknown[],
sentIds: string[]
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PgpBlockViewErrorModule {
}
};

public handleInitializeErr = async (e: any) => {
public handleInitializeErr = async (e: unknown) => {
if (ApiErr.isNetErr(e)) {
await this.renderErr(`Could not load message due to network error. ${Ui.retryLink()}`, undefined);
} else if (ApiErr.isAuthErr(e)) {
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/settings/modules/debug_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ View.run(class DebugApiView extends View {
// No need
};

private renderCallRes = (api: string, variables: Dict<any>, result: any, error?: any) => {
private renderCallRes = (api: string, variables: Dict<unknown>, result: unknown, error?: unknown) => {
const r = `<b>${api} ${JSON.stringify(variables)}</b><pre data-test="container-pre">${JSON.stringify(result, undefined, 2)} (${error ? JSON.stringify(error) : 'no err'})</pre>`;
Xss.sanitizeAppend('#content', r);
};
Expand Down
4 changes: 3 additions & 1 deletion extension/chrome/settings/modules/my_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { KeyStore } from '../../../js/common/platform/store/key-store.js';
import { Xss } from '../../../js/common/platform/xss.js';
import { FlowCryptWebsite } from '../../../js/common/api/flowcrypt-website.js';

declare const ClipboardJS: any;
declare class ClipboardJS {
constructor(selector: string, options: {});
}

View.run(class MyKeyView extends View {

Expand Down
2 changes: 1 addition & 1 deletion extension/js/background_page/bgutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BgUtils {
});
};

public static handleStoreErr = async (e: any, reason?: 'storage_undefined' | 'db_corrupted' | 'db_denied' | 'db_failed') => {
public static handleStoreErr = async (e: unknown, reason?: 'storage_undefined' | 'db_corrupted' | 'db_denied' | 'db_failed') => {
if (!reason) {
if (e instanceof StoreCorruptedError) {
reason = 'db_corrupted';
Expand Down
8 changes: 4 additions & 4 deletions extension/js/common/api/email-provider/gmail/google-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class GoogleAuth {
throw new GoogleAuthErr(`Could not refresh google auth token - did not become valid (access:${refreshTokenRes.access_token},expires_in:${refreshTokenRes.expires_in},now:${Date.now()})`);
};

public static apiGoogleCallRetryAuthErrorOneTime = async (acctEmail: string, request: JQuery.AjaxSettings): Promise<any> => {
public static apiGoogleCallRetryAuthErrorOneTime = async (acctEmail: string, request: JQuery.AjaxSettings): Promise<unknown> => {
try {
return await Api.ajax(request, Catch.stackTrace());
} catch (firstAttemptErr) {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class GoogleAuth {
/**
* Happens on enterprise builds
*/
public static isFesUnreachableErr = (e: any, email: string): boolean => {
public static isFesUnreachableErr = (e: unknown, email: string): boolean => {
const domain = Str.getDomainFromEmailAddress(email);
const errString = String(e);
if (errString.includes(`-1 when GET-ing https://fes.${domain}/api/ `)) { // the space is important to match the full url
Expand Down Expand Up @@ -301,7 +301,7 @@ export class GoogleAuth {
method: 'POST',
crossDomain: true,
async: true,
}, Catch.stackTrace()) as any as GoogleAuthTokensResponse;
}, Catch.stackTrace()) as unknown as GoogleAuthTokensResponse;
};

private static googleAuthRefreshToken = async (refreshToken: string) => {
Expand All @@ -310,7 +310,7 @@ export class GoogleAuth {
method: 'POST',
crossDomain: true,
async: true,
}, Catch.stackTrace()) as any as GoogleAuthTokensResponse;
}, Catch.stackTrace()) as unknown as GoogleAuthTokensResponse;
};

// todo - would be better to use a TS type guard instead of the type cast when checking OpenId
Expand Down
32 changes: 16 additions & 16 deletions extension/js/common/api/shared/api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class AjaxErr extends ApiCallErr { // no static props, else will get seri
}

export class ApiErr {
public static eli5 = (e: any): string => { // "explain like I'm five"
public static eli5 = (e: unknown): string => { // "explain like I'm five"
if (ApiErr.isMailOrAcctDisabledOrPolicy(e)) {
return 'Email account is disabled, or access has been blocked by admin policy. Contact your email administrator.';
} else if (ApiErr.isAuthErr(e)) {
Expand Down Expand Up @@ -174,7 +174,7 @@ export class ApiErr {
}
};

public static isStandardErr = (e: any, internalType: 'auth' | 'subscription'): boolean => {
public static isStandardErr = (e: unknown, internalType: 'auth' | 'subscription'): boolean => {
if (!e || !(typeof e === 'object')) {
return false;
}
Expand All @@ -190,7 +190,7 @@ export class ApiErr {
return false;
};

public static isAuthErr = (e: any): boolean => {
public static isAuthErr = (e: unknown): boolean => {
if (e instanceof AuthErr || e instanceof GoogleAuthErr) {
return true;
}
Expand All @@ -214,7 +214,7 @@ export class ApiErr {
return false;
};

public static isMailOrAcctDisabledOrPolicy = (e: any): boolean => {
public static isMailOrAcctDisabledOrPolicy = (e: unknown): boolean => {
if (e instanceof AjaxErr && ApiErr.isBadReq(e) && typeof e.responseText === 'string') {
if (e.responseText.indexOf('Mail service not enabled') !== -1 || e.responseText.indexOf('Account has been deleted') !== -1) {
return true;
Expand All @@ -226,7 +226,7 @@ export class ApiErr {
return false;
};

public static isBlockedByProxy = (e: any): boolean => {
public static isBlockedByProxy = (e: unknown): boolean => {
if (!(e instanceof AjaxErr)) {
return false;
}
Expand All @@ -241,7 +241,7 @@ export class ApiErr {
return false;
};

public static isNetErr = (e: any): e is Error => {
public static isNetErr = (e: unknown): e is Error => {
if (e instanceof TypeError && (e.message === 'Failed to fetch' || e.message === 'NetworkError when attempting to fetch resource.')) {
return true; // openpgp.js uses fetch()... which produces these errors
}
Expand All @@ -257,38 +257,38 @@ export class ApiErr {
return false;
};

public static isDecryptErr = (e: any): e is DecryptionError => {
public static isDecryptErr = (e: unknown): e is DecryptionError => {
if (e instanceof DecryptionError) {
return true;
}
return false;
};

public static isSignificant = (e: any): boolean => {
public static isSignificant = (e: unknown): boolean => {
return !ApiErr.isNetErr(e) && !ApiErr.isServerErr(e) && !ApiErr.isNotFound(e) && !ApiErr.isMailOrAcctDisabledOrPolicy(e)
&& !ApiErr.isAuthErr(e) && !ApiErr.isBlockedByProxy(e);
};

public static isBadReq = (e: any): e is AjaxErr => {
public static isBadReq = (e: unknown): e is AjaxErr => {
return e instanceof AjaxErr && e.status === 400;
};
public static isInsufficientPermission = (e: any): e is AjaxErr => {
public static isInsufficientPermission = (e: unknown): e is AjaxErr => {
return e instanceof AjaxErr && e.status === 403 && e.responseText.indexOf('insufficientPermissions') !== -1;
};

public static isNotFound = (e: any): e is AjaxErr => {
public static isNotFound = (e: unknown): e is AjaxErr => {
return e instanceof AjaxErr && e.status === 404;
};

public static isReqTooLarge = (e: any): boolean => {
public static isReqTooLarge = (e: unknown): boolean => {
return e instanceof AjaxErr && e.status === 413;
};

public static isServerErr = (e: any): boolean => {
public static isServerErr = (e: unknown): boolean => {
return e instanceof AjaxErr && e.status >= 500;
};

public static detailsAsHtmlWithNewlines = (e: any): string => {
public static detailsAsHtmlWithNewlines = (e: unknown): string => {
let details = 'Below are technical details about the error. This may be useful for debugging.\n\n';
details += `<b>Error string</b>: ${Xss.escape(String(e))}\n\n`;
details += `<b>Error stack</b>: ${e instanceof Error ? Xss.escape((e.stack || '(empty)')) : '(no error stack)'}\n\n`;
Expand All @@ -298,11 +298,11 @@ export class ApiErr {
return details;
};

public static isInPrivateMode = (e: any) => {
public static isInPrivateMode = (e: unknown) => {
return e instanceof Error && e.message.startsWith('BrowserMsg() (no status text): -1 when GET-ing blob:moz-extension://');
};

public static reportIfSignificant = (e: any) => {
public static reportIfSignificant = (e: unknown) => {
if (ApiErr.isSignificant(e)) {
Catch.reportErr(e);
}
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Assert {
throw new Error(`urlParamRequire.optionalString: type of ${name} unexpectedly ${typeof r}`);
},
oneof: <T>(values: UrlParams, name: string, allowed: T[]): T => {
return Assert.abortAndRenderErrOnUrlParamValMismatch(values, name, allowed as any as UrlParam[]) as any as T; // todo - there should be a better way
return Assert.abortAndRenderErrOnUrlParamValMismatch(values, name, allowed as unknown as UrlParam[]) as unknown as T; // todo - there should be a better way
},
};

Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/browser/browser-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FlatTypes } from '../platform/store/abstract-store.js';

export class BrowserExtension { // todo - move extension-specific common.js code here

public static prepareBugReport = (name: string, details?: Dict<FlatTypes>, error?: Error | any): string => {
public static prepareBugReport = (name: string, details?: Dict<FlatTypes>, error?: Error | unknown): string => {
const bugReport: Dict<string> = { name, stack: Catch.stackTrace() };
try {
bugReport.error = JSON.stringify(error, undefined, 2);
Expand Down
8 changes: 4 additions & 4 deletions extension/js/common/browser/browser-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export type GoogleAuthWindowResult$result = 'Success' | 'Denied' | 'Error' | 'Cl
export namespace Bm {
export type Dest = string;
export type Sender = chrome.runtime.MessageSender | 'background';
export type Response = any;
export type RawResponse = { result: any, objUrls: { [name: string]: string }, exception?: Bm.ErrAsJson };
export type Response = unknown;
export type RawResponse = { result: unknown, objUrls: { [name: string]: string }, exception?: Bm.ErrAsJson };
export type Raw = { name: string; data: { bm: AnyRequest | {}, objUrls: Dict<string> }; to: Dest | null; uid: string; stack: string };

export type SetCss = { css: Dict<string>, traverseUp?: number, selector: string; };
Expand All @@ -47,7 +47,7 @@ export namespace Bm {
export type OpenGoogleAuthDialog = { acctEmail?: string, scopes?: string[] };
export type OpenPage = { page: string, addUrlText?: string | UrlParams };
export type PassphraseEntry = { entered: boolean, initiatorFrameId?: string };
export type Db = { f: string, args: any[] };
export type Db = { f: string, args: unknown[] };
export type InMemoryStoreSet = { acctEmail: string, key: string, value: string | undefined, expiration: number | undefined };
export type InMemoryStoreGet = { acctEmail: string, key: string };
export type StoreGlobalGet = { keys: GlobalIndex[]; };
Expand Down Expand Up @@ -461,7 +461,7 @@ export class BrowserMsg {
return requestOrResponse;
};

private static errToJson = (e: any): Bm.ErrAsJson => {
private static errToJson = (e: unknown): Bm.ErrAsJson => {
if (e instanceof AjaxErr) {
const { message, stack, status, url, responseText, statusText, resMsg, resDetails } = e;
return { stack, message, errorConstructor: 'AjaxErr', ajaxErrorDetails: { status, url, responseText, statusText, resMsg, resDetails } };
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/browser/browser-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type AnyThirdPartyLibrary = any;
export type AddrParserResult = { name?: string, address?: string };

export interface BrowserWindow extends Window {
onunhandledrejection: (e: any) => void;
onunhandledrejection: (e: unknown) => void;
'emailjs-mime-codec': AnyThirdPartyLibrary;
'emailjs-mime-parser': AnyThirdPartyLibrary;
'emailjs-mime-builder': AnyThirdPartyLibrary;
Expand Down
6 changes: 3 additions & 3 deletions extension/js/common/browser/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const handleFatalErr = (reason: 'storage_undefined', error: Error) => {
} catch (e) {
if (e && e instanceof Error && e.message === 'Extension context invalidated.') {
console.info(`FlowCrypt cannot handle fatal error because: Extension context invalidated. Destroying.`, error);
(window as any as ContentScriptWindow).destroy();
(window as unknown as ContentScriptWindow).destroy();
} else {
throw e;
}
Expand Down Expand Up @@ -62,7 +62,7 @@ export const storageLocalGet = async (keys: string[]): Promise<Dict<unknown>> =>
});
};

export const storageLocalGetAll = async (): Promise<{ [key: string]: any }> => {
export const storageLocalGetAll = async (): Promise<{ [key: string]: unknown }> => {
return await new Promise((resolve) => {
if (typeof chrome.storage === 'undefined') {
handleFatalErr('storage_undefined', new Error('storage is undefined'));
Expand All @@ -72,7 +72,7 @@ export const storageLocalGetAll = async (): Promise<{ [key: string]: any }> => {
});
};

export const storageLocalSet = async (values: Dict<any>): Promise<void> => {
export const storageLocalSet = async (values: Dict<unknown>): Promise<void> => {
return await new Promise((resolve) => {
if (typeof chrome.storage === 'undefined') {
handleFatalErr('storage_undefined', new Error('storage is undefined'));
Expand Down
4 changes: 2 additions & 2 deletions extension/js/common/browser/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ProvidedEventHandler = (e: HTMLElement, event: JQuery.Event<HTMLElement, nu

export type SelCache = { cached: (name: string) => JQuery<HTMLElement>; now: (name: string) => JQuery<HTMLElement>; sel: (name: string) => string; };
export type PreventableEventName = 'double' | 'parallel' | 'spree' | 'slowspree' | 'veryslowspree';
export type BrowserEventErrHandler = { auth?: () => Promise<void>, authPopup?: () => Promise<void>, network?: () => Promise<void>, other?: (e: any) => Promise<void> };
export type BrowserEventErrHandler = { auth?: () => Promise<void>, authPopup?: () => Promise<void>, network?: () => Promise<void>, other?: (e: unknown) => Promise<void> };

export class Ui {

Expand Down Expand Up @@ -53,7 +53,7 @@ export class Ui {
}
};
},
_dispatchErr: (e: any, errHandlers?: BrowserEventErrHandler) => {
_dispatchErr: (e: unknown, errHandlers?: BrowserEventErrHandler) => {
if (ApiErr.isNetErr(e) && errHandlers && errHandlers.network) {
errHandlers.network().catch(Catch.reportErr);
} else if (ApiErr.isAuthErr(e) && errHandlers && errHandlers.auth) {
Expand Down
Loading