Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

stricter types on ts-lib types (#109)

Myles Scolnickc3a8a0a0b752
diff --git a/frontend/src/core/dom/htmlUtils.ts b/frontend/src/core/dom/htmlUtils.ts
index d0654cea77..9c218c56a4 100644
--- a/frontend/src/core/dom/htmlUtils.ts
+++ b/frontend/src/core/dom/htmlUtils.ts
@@ -33,7 +33,7 @@ export function parseAttrValue<T>(value: string | undefined): T {
return Number.NEGATIVE_INFINITY;
}
return v;
- });
+ }) as T;
} catch {
return {} as T;
}
diff --git a/frontend/src/core/network/api.ts b/frontend/src/core/network/api.ts
index cecf8eb445..29c698a3ca 100644
--- a/frontend/src/core/network/api.ts
+++ b/frontend/src/core/network/api.ts
@@ -31,9 +31,9 @@ export const API = {
} else if (
response.headers.get("Content-Type")?.startsWith("application/json")
) {
- return response.json();
+ return response.json() as RESP;
} else {
- return null;
+ return null as RESP;
}
})
.catch((error) => {
diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsx
index b8fb1d9d01..858725665e 100644
--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx
+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx
@@ -46,7 +46,7 @@ export function useMarimoWebSocket(opts: {
* Message callback. Handle messages sent by the kernel.
*/
onMessage: (e: MessageEvent<string>) => {
- const msg: OperationMessage = JSON.parse(e.data);
+ const msg = JSON.parse(e.data) as OperationMessage;
switch (msg.op) {
case "kernel-ready": {
const { codes, names } = msg.data;
diff --git a/frontend/src/custom.d.ts b/frontend/src/custom.d.ts
index aae3c1b28e..a4057ee30e 100644
--- a/frontend/src/custom.d.ts
+++ b/frontend/src/custom.d.ts
@@ -1,5 +1,24 @@
/* Copyright 2023 Marimo. All rights reserved. */
+/* eslint-disable @typescript-eslint/no-explicit-any */
declare module "*.svg" {
const content: string | undefined;
export default content;
}
+
+// Stricter lib types
+interface Body {
+ json(): Promise<unknown>;
+}
+
+// Stricter lib types
+interface JSON {
+ parse(
+ text: string,
+ reviver?: (this: any, key: string, value: any) => any
+ ): unknown;
+}
+
+// Improve type inference for Array.filter with BooleanConstructor
+interface Array<T> {
+ filter(predicate: BooleanConstructor): Array<NonNullable<T>>;
+}
diff --git a/frontend/src/editor/Output.tsx b/frontend/src/editor/Output.tsx
index 2dfa1aafaf..7719095834 100644
--- a/frontend/src/editor/Output.tsx
+++ b/frontend/src/editor/Output.tsx
@@ -92,7 +92,8 @@ export const OutputArea = React.memo(
>
{formatOutput({
message: props.output,
- parsedJsonData: parsedJsonData,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ parsedJsonData: parsedJsonData as Record<string, any>,
})}
</div>
);