Skip to content

Commit

Permalink
Typescript config parity with Browsertrix repo (#289)
Browse files Browse the repository at this point in the history
Follow-up from #288 

This matches the strictness rules with the Browsertrix repo,
specifically `noImplicitAny`, and then adds `// @ts-expect-error`s to
suppress existing errors this change raises. This'll help us keep code
quality high moving forward.

Going to just directly merge this once it passes CI; as with #288, this
doesn't change any code, just comments.
  • Loading branch information
emma-sg committed Mar 8, 2024
1 parent 40d84f3 commit 5c7b914
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/appmain.ts
Expand Up @@ -480,6 +480,7 @@ export class ReplayWebApp extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onFavIcons(event) {
const head = document.querySelector("head")!;
const oldLinks = document.querySelectorAll("link[rel*='icon']");
Expand All @@ -496,13 +497,15 @@ export class ReplayWebApp extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
skipMenu(event) {
// This is a workaround, since this app's routing doesn't permit normal
// following of in-page anchors.
event.preventDefault();
this.renderRoot.querySelector<HTMLElement>("#skip-main-target")?.focus();
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onNavMenu(event) {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -644,6 +647,7 @@ export class ReplayWebApp extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onStartLoad(event) {
// just redirect right away?
// TODO: Fix this the next time the file is edited.
Expand All @@ -665,6 +669,7 @@ export class ReplayWebApp extends LitElement {
this.loadInfo = event.detail;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onCollLoaded(event) {
this.loadInfo = null;
if (event.detail.collInfo) {
Expand All @@ -687,6 +692,7 @@ export class ReplayWebApp extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onTitle(event) {
if (event.detail.title) {
this.pageTitle = event.detail.title;
Expand Down
7 changes: 6 additions & 1 deletion src/chooser.ts
Expand Up @@ -77,6 +77,7 @@ export class Chooser extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onChooseFile(event) {
if (event.currentTarget.files.length === 0) {
return;
Expand Down Expand Up @@ -167,6 +168,7 @@ export class Chooser extends LitElement {
return false;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onInput(event) {
this.fileDisplayName = event.currentTarget.value;

Expand Down Expand Up @@ -255,7 +257,10 @@ export class Chooser extends LitElement {
${!this.hasNativeFS
? html` <input
class="file-input"
@click="${(e) => (e.currentTarget.value = null)}"
@click="${
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'e' implicitly has an 'any' type.
(e) => (e.currentTarget.value = null)
}"
@change=${this.onChooseFile}
type="file"
id="fileupload"
Expand Down
5 changes: 5 additions & 0 deletions src/electron-preload.ts
@@ -1,5 +1,6 @@
/*eslint-env node */

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/loaders'. 'node_modules/@webrecorder/wabac/src/loaders.js' implicitly has an 'any' type.
import { CollectionLoader } from "@webrecorder/wabac/src/loaders";
import { type IpcRendererEvent } from "electron";

Expand All @@ -12,11 +13,15 @@ const dbs = {};
const loader = new CollectionLoader();

async function getColl(name: string) {
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
if (!dbs[name]) {
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
dbs[name] = await loader.loadColl(name);
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
await dbs[name].initing;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return dbs[name];
Expand Down
14 changes: 12 additions & 2 deletions src/electron-replay-app.ts
Expand Up @@ -16,13 +16,15 @@ import {
import path from "path";
import fs from "fs";

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/rewrite'. 'node_modules/@webrecorder/wabac/src/rewrite/index.js' implicitly has an 'any' type.
import { ArchiveResponse, Rewriter } from "@webrecorder/wabac/src/rewrite";

import { PassThrough, Readable } from "stream";

import { autoUpdater } from "electron-updater";
import log from "electron-log";

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7016 - Could not find a declaration file for module 'mime-types'. 'node_modules/mime-types/index.js' implicitly has an 'any' type.
import mime from "mime-types";
import url from "url";

Expand Down Expand Up @@ -214,6 +216,7 @@ class ElectronReplayApp {
this.mainWindow = this.createMainWindow(process.argv);
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'request' implicitly has an 'any' type. | TS7006 - Parameter 'callback' implicitly has an 'any' type.
async doHandleFile(request, callback) {
//const parsedUrl = new URL(request.url);
//const filename = parsedUrl.searchParams.get("filename");
Expand Down Expand Up @@ -259,6 +262,7 @@ class ElectronReplayApp {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'data' implicitly has an 'any' type.
_bufferToStream(data) {
const rv = new PassThrough();
rv.push(data);
Expand All @@ -267,6 +271,7 @@ class ElectronReplayApp {
}

async doIntercept(
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'request' implicitly has an 'any' type.
request,
callback: (response: {
statusCode: number;
Expand Down Expand Up @@ -337,6 +342,7 @@ class ElectronReplayApp {
await this.proxyLive(request, callback);
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'request' implicitly has an 'any' type. | TS7006 - Parameter 'callback' implicitly has an 'any' type.
async proxyLive(request, callback) {
let headers = request.headers;
const { method, url, uploadData } = request;
Expand Down Expand Up @@ -364,8 +370,6 @@ class ElectronReplayApp {
const data = method === "HEAD" ? null : response.body;
const statusCode = response.status;

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
headers = Object.fromEntries(response.headers.entries());
callback({ statusCode, headers, data });
}
Expand All @@ -379,6 +383,7 @@ class ElectronReplayApp {
* data: unknown;
* }) => void} callback
*/
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'url' implicitly has an 'any' type. | TS7006 - Parameter 'callback' implicitly has an 'any' type.
notFound(url, callback) {
console.log("not found: " + url);
const data = this._bufferToStream(
Expand All @@ -391,6 +396,7 @@ class ElectronReplayApp {
});
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'request' implicitly has an 'any' type. | TS7006 - Parameter 'callback' implicitly has an 'any' type.
async resolveArchiveResponse(request, callback) {
const channel = `req:${new Date().getTime()}:${request.url}`;

Expand Down Expand Up @@ -469,6 +475,7 @@ class ElectronReplayApp {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'reqHeaders' implicitly has an 'any' type. | TS7006 - Parameter 'headers' implicitly has an 'any' type. | TS7006 - Parameter 'size' implicitly has an 'any' type.
parseRange(reqHeaders, headers, size) {
let statusCode = 200;
const range = reqHeaders.get("range");
Expand All @@ -495,6 +502,7 @@ class ElectronReplayApp {
return { statusCode, start, end };
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'argv' implicitly has an 'any' type.
createMainWindow(argv) {
const sourceString = this.getOpenUrl(argv);

Expand All @@ -521,6 +529,7 @@ class ElectronReplayApp {
return theWindow;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'argv' implicitly has an 'any' type.
getOpenUrl(argv) {
argv = require("minimist")(argv.slice(process.defaultApp ? 2 : 1));

Expand Down Expand Up @@ -565,6 +574,7 @@ class ElectronReplayApp {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'body' implicitly has an 'any' type. | TS7006 - Parameter 'session' implicitly has an 'any' type.
async function* readBody(body, session) {
for (const chunk of body) {
if (chunk.bytes) {
Expand Down
1 change: 1 addition & 0 deletions src/embed-receipt.ts
Expand Up @@ -357,6 +357,7 @@ export class RWPEmbedReceipt extends LitElement {
`;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onEmbedDrop(event) {
event.stopPropagation();
this.active = !this.active;
Expand Down
6 changes: 6 additions & 0 deletions src/embed.ts
Expand Up @@ -24,7 +24,9 @@ class Embed extends LitElement {
@property({ type: String }) ts = "";
@property({ type: String }) query = "";

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7008 - Member 'source' implicitly has an 'any' type.
@property({ type: String }) source;
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7008 - Member 'src' implicitly has an 'any' type.
@property({ type: String }) src;

@property({ type: String }) view = "replay";
Expand Down Expand Up @@ -57,6 +59,7 @@ class Embed extends LitElement {
| string
| undefined;

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7008 - Member 'requireSubdomainIframe' implicitly has an 'any' type.
@property({ type: Boolean }) requireSubdomainIframe;

@property({ type: String }) loading = "";
Expand All @@ -73,6 +76,7 @@ class Embed extends LitElement {
isCrossOrigin: boolean | undefined;
swmanager: SWManager | undefined;

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'replayfile' implicitly has an 'any' type.
static setDefaultReplayFile(replayfile) {
defaultReplayFile = replayfile;
}
Expand Down Expand Up @@ -109,6 +113,7 @@ class Embed extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
handleMessage(event) {
const iframe = this.renderRoot.querySelector("iframe");

Expand Down Expand Up @@ -353,6 +358,7 @@ class Embed extends LitElement {
`;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
onLoad(event) {
if (this.isCrossOrigin) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/gdrive.ts
Expand Up @@ -97,6 +97,7 @@ class GDrive extends LitElement {

onLoad() {
this.scriptLoaded = true;
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'response' implicitly has an 'any' type.
this.gauth("none", (response) => {
if (response.error) {
if (this.state !== "implicitonly") {
Expand All @@ -111,6 +112,7 @@ class GDrive extends LitElement {
}

onClickAuth() {
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'response' implicitly has an 'any' type.
this.gauth("select_account", (response) => {
if (!response.error) {
// TODO: Fix this the next time the file is edited.
Expand All @@ -120,6 +122,7 @@ class GDrive extends LitElement {
});
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'response' implicitly has an 'any' type.
async authed(response) {
const sourceUrl = this.sourceUrl;
const fileId = sourceUrl.slice("googledrive://".length);
Expand Down Expand Up @@ -200,6 +203,7 @@ class GDrive extends LitElement {
return script;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'prompt' implicitly has an 'any' type. | TS7006 - Parameter 'callback' implicitly has an 'any' type.
gauth(prompt, callback) {
self.gapi.load("auth2", () => {
self.gapi.auth2.authorize(
Expand Down
1 change: 1 addition & 0 deletions src/item-index.ts
Expand Up @@ -120,6 +120,7 @@ class ItemIndex extends LitElement {
}
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
async onDeleteItem(event) {
event.preventDefault();
event.stopPropagation();
Expand Down
1 change: 1 addition & 0 deletions src/item-info.ts
Expand Up @@ -240,6 +240,7 @@ class ItemInfo extends LitElement {
return false;
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'reload' implicitly has an 'any' type.
onPurge(reload) {
const detail = { reload };
this.dispatchEvent(new CustomEvent("item-purge", { detail }));
Expand Down

0 comments on commit 5c7b914

Please sign in to comment.