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.

chore(frontend): Simplify and tighten TypeScript configuration (#5413)

Trevor Manz80a17194c847
diff --git a/frontend/src/components/datasources/__tests__/utils.test.ts b/frontend/src/components/datasources/__tests__/utils.test.ts
index b3be5889ab..423f119f40 100644
--- a/frontend/src/components/datasources/__tests__/utils.test.ts
+++ b/frontend/src/components/datasources/__tests__/utils.test.ts
@@ -1,10 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { describe, expect, it } from "vitest";
-import {
- DUCKDB_ENGINE,
- type SQLTableContext,
-} from "@/core/datasets/data-source-connections";
+import type { SQLTableContext } from "@/core/datasets/data-source-connections";
+import { DUCKDB_ENGINE } from "@/core/datasets/engines";
import type { DataTable, DataTableColumn } from "@/core/kernel/messages";
import { sqlCode } from "../utils";
diff --git a/frontend/src/components/datasources/datasources.tsx b/frontend/src/components/datasources/datasources.tsx
index 56e1b88e18..c969297e3e 100644
--- a/frontend/src/components/datasources/datasources.tsx
+++ b/frontend/src/components/datasources/datasources.tsx
@@ -29,12 +29,11 @@ import { cellIdsAtom, useCellActions } from "@/core/cells/cells";
import { useLastFocusedCellId } from "@/core/cells/focus";
import { autoInstantiateAtom } from "@/core/config/config";
import {
- DUCKDB_ENGINE,
dataConnectionsMapAtom,
- INTERNAL_SQL_ENGINES,
type SQLTableContext,
useDataSourceActions,
} from "@/core/datasets/data-source-connections";
+import { DUCKDB_ENGINE, INTERNAL_SQL_ENGINES } from "@/core/datasets/engines";
import {
PreviewSQLTable,
PreviewSQLTableList,
diff --git a/frontend/src/components/datasources/utils.ts b/frontend/src/components/datasources/utils.ts
index 27e34afaf9..ef4d9f1909 100644
--- a/frontend/src/components/datasources/utils.ts
+++ b/frontend/src/components/datasources/utils.ts
@@ -1,8 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import {
- DUCKDB_ENGINE,
- type SQLTableContext,
-} from "@/core/datasets/data-source-connections";
+import type { SQLTableContext } from "@/core/datasets/data-source-connections";
+import { DUCKDB_ENGINE } from "@/core/datasets/engines";
import type { DataTable, DataType } from "@/core/kernel/messages";
import type { ColumnHeaderStatsKey } from "../data-table/types";
diff --git a/frontend/src/components/editor/RecoveryButton.tsx b/frontend/src/components/editor/RecoveryButton.tsx
index 1e3b006147..f8c4a06ee6 100644
--- a/frontend/src/components/editor/RecoveryButton.tsx
+++ b/frontend/src/components/editor/RecoveryButton.tsx
@@ -1,10 +1,10 @@
/* Copyright 2024 Marimo. All rights reserved. */
import type { Notebook } from "@marimo-team/marimo-api";
-import { Button } from "components/ui/button";
import { SaveIcon } from "lucide-react";
import type { JSX } from "react";
import { Button as EditorButton } from "@/components/editor/inputs/Inputs";
+import { Button } from "@/components/ui/button";
import { getNotebook } from "@/core/cells/cells";
import { notebookCells } from "@/core/cells/utils";
import { getMarimoVersion } from "@/core/meta/globals";
diff --git a/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts b/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts
index 61d1473df3..7ef076d47c 100644
--- a/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts
+++ b/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts
@@ -1,10 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { beforeEach, describe, expect, it, type Mock, vi } from "vitest";
import { getCodes } from "@/core/codemirror/copilot/getCodes";
-import {
- DUCKDB_ENGINE,
- dataSourceConnectionsAtom,
-} from "@/core/datasets/data-source-connections";
+import { dataSourceConnectionsAtom } from "@/core/datasets/data-source-connections";
+import { DUCKDB_ENGINE } from "@/core/datasets/engines";
import { datasetsAtom } from "@/core/datasets/state";
import type { DatasetsState } from "@/core/datasets/types";
import { store } from "@/core/state/jotai";
diff --git a/frontend/src/components/slides/slides-component.tsx b/frontend/src/components/slides/slides-component.tsx
index 71861300a8..a74c4dd9f4 100644
--- a/frontend/src/components/slides/slides-component.tsx
+++ b/frontend/src/components/slides/slides-component.tsx
@@ -14,12 +14,6 @@ import { useEventListener } from "@/hooks/useEventListener";
import { cn } from "@/utils/cn";
import "./slides.css";
-import "swiper/css";
-import "swiper/css/virtual";
-import "swiper/css/keyboard";
-import "swiper/css/navigation";
-import "swiper/css/pagination";
-import "swiper/css/scrollbar";
interface SlidesComponentProps {
className?: string;
diff --git a/frontend/src/components/slides/slides.css b/frontend/src/components/slides/slides.css
index 52e20e2f25..bc54dcfeb5 100644
--- a/frontend/src/components/slides/slides.css
+++ b/frontend/src/components/slides/slides.css
@@ -1,3 +1,10 @@
+@import "swiper/css";
+@import "swiper/css/virtual";
+@import "swiper/css/keyboard";
+@import "swiper/css/navigation";
+@import "swiper/css/pagination";
+@import "swiper/css/scrollbar";
+
.mo-slides-theme {
--swiper-theme-color: var(--primary);
--swiper-pagination-color: var(--swiper-theme-color);
diff --git a/frontend/src/core/codemirror/language/__tests__/extension.test.ts b/frontend/src/core/codemirror/language/__tests__/extension.test.ts
index 4f90c110b1..a2b4e36694 100644
--- a/frontend/src/core/codemirror/language/__tests__/extension.test.ts
+++ b/frontend/src/core/codemirror/language/__tests__/extension.test.ts
@@ -4,7 +4,7 @@ import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { describe, expect, it } from "vitest";
import type { CellId } from "@/core/cells/ids";
-import { DUCKDB_ENGINE } from "@/core/datasets/data-source-connections";
+import { DUCKDB_ENGINE } from "@/core/datasets/engines";
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
import { cellConfigExtension } from "../../config/extension";
import {
diff --git a/frontend/src/core/codemirror/language/__tests__/sql.test.ts b/frontend/src/core/codemirror/language/__tests__/sql.test.ts
index 25245b0bbe..faf3f3e0c2 100644
--- a/frontend/src/core/codemirror/language/__tests__/sql.test.ts
+++ b/frontend/src/core/codemirror/language/__tests__/sql.test.ts
@@ -3,11 +3,10 @@
import { PostgreSQL } from "@codemirror/lang-sql";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
- type ConnectionName,
- DUCKDB_ENGINE,
dataSourceConnectionsAtom,
setLatestEngineSelected,
} from "@/core/datasets/data-source-connections";
+import { type ConnectionName, DUCKDB_ENGINE } from "@/core/datasets/engines";
import { datasetsAtom } from "@/core/datasets/state";
import type { DatasetsState } from "@/core/datasets/types";
import type { DataSourceConnection } from "@/core/kernel/messages";
diff --git a/frontend/src/core/codemirror/language/languages/sql.ts b/frontend/src/core/codemirror/language/languages/sql.ts
index 8d2967b4f5..6cc50fc679 100644
--- a/frontend/src/core/codemirror/language/languages/sql.ts
+++ b/frontend/src/core/codemirror/language/languages/sql.ts
@@ -23,12 +23,11 @@ import { parser } from "@lezer/python";
import dedent from "string-dedent";
import { isSchemaless } from "@/components/datasources/utils";
import {
- type ConnectionName,
- DUCKDB_ENGINE,
dataConnectionsMapAtom,
dataSourceConnectionsAtom,
setLatestEngineSelected,
} from "@/core/datasets/data-source-connections";
+import { type ConnectionName, DUCKDB_ENGINE } from "@/core/datasets/engines";
import { datasetTablesAtom } from "@/core/datasets/state";
import type { DataSourceConnection } from "@/core/kernel/messages";
import { store } from "@/core/state/jotai";
diff --git a/frontend/src/core/codemirror/language/panel/sql.tsx b/frontend/src/core/codemirror/language/panel/sql.tsx
index 4297ebde16..78b97dc906 100644
--- a/frontend/src/core/codemirror/language/panel/sql.tsx
+++ b/frontend/src/core/codemirror/language/panel/sql.tsx
@@ -15,11 +15,13 @@ import {
SelectValue,
} from "@/components/ui/select";
import {
- type ConnectionName,
dataConnectionsMapAtom,
- INTERNAL_SQL_ENGINES,
setLatestEngineSelected,
} from "@/core/datasets/data-source-connections";
+import {
+ type ConnectionName,
+ INTERNAL_SQL_ENGINES,
+} from "@/core/datasets/engines";
import type { DataSourceConnection } from "@/core/kernel/messages";
import { useNonce } from "@/hooks/useNonce";
diff --git a/frontend/src/core/datasets/__tests__/all-tables.test.ts b/frontend/src/core/datasets/__tests__/all-tables.test.ts
index 82b02c336d..10b16ad02b 100644
--- a/frontend/src/core/datasets/__tests__/all-tables.test.ts
+++ b/frontend/src/core/datasets/__tests__/all-tables.test.ts
@@ -4,9 +4,9 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { store } from "@/core/state/jotai";
import {
allTablesAtom,
- DUCKDB_ENGINE,
dataSourceConnectionsAtom,
} from "../data-source-connections";
+import { DUCKDB_ENGINE } from "../engines";
import { datasetsAtom } from "../state";
import type { DatasetsState } from "../types";
diff --git a/frontend/src/core/datasets/__tests__/data-source.test.ts b/frontend/src/core/datasets/__tests__/data-source.test.ts
index 69534adbd0..ae37beb119 100644
--- a/frontend/src/core/datasets/__tests__/data-source.test.ts
+++ b/frontend/src/core/datasets/__tests__/data-source.test.ts
@@ -3,13 +3,12 @@ import { beforeEach, describe, expect, it } from "vitest";
import type { DataTable } from "@/core/kernel/messages";
import type { VariableName } from "@/core/variables/types";
import {
- type ConnectionName,
type DataSourceConnection,
type DataSourceState,
exportedForTesting,
- INTERNAL_SQL_ENGINES,
type SQLTableContext,
} from "../data-source-connections";
+import { type ConnectionName, INTERNAL_SQL_ENGINES } from "../engines";
const { reducer, initialState } = exportedForTesting;
diff --git a/frontend/src/core/datasets/data-source-connections.ts b/frontend/src/core/datasets/data-source-connections.ts
index df08d5a347..e9ea8de93f 100644
--- a/frontend/src/core/datasets/data-source-connections.ts
+++ b/frontend/src/core/datasets/data-source-connections.ts
@@ -4,23 +4,19 @@ import { atom } from "jotai";
import { isSchemaless } from "@/components/datasources/utils";
import { createReducerAndAtoms } from "@/utils/createReducer";
import { Logger } from "@/utils/Logger";
-import type { TypedString } from "@/utils/typed";
import type {
DataSourceConnection as DataSourceConnectionType,
DataTable,
} from "../kernel/messages";
import { store } from "../state/jotai";
import type { VariableName } from "../variables/types";
+import {
+ type ConnectionName,
+ DUCKDB_ENGINE,
+ INTERNAL_SQL_ENGINES,
+} from "./engines";
import { datasetTablesAtom } from "./state";
-export type ConnectionName = TypedString<"ConnectionName">;
-
-// DuckDB engine is treated as the default engine
-// As it doesn't require passing an engine variable to the backend
-// Keep this in sync with the backend name
-export const DUCKDB_ENGINE = "__marimo_duckdb" as ConnectionName;
-export const INTERNAL_SQL_ENGINES = new Set([DUCKDB_ENGINE]);
-
const initialConnections: ConnectionsMap = new Map([
[
DUCKDB_ENGINE,
diff --git a/frontend/src/core/datasets/engines.ts b/frontend/src/core/datasets/engines.ts
new file mode 100644
index 0000000000..978b5f74f0
--- /dev/null
+++ b/frontend/src/core/datasets/engines.ts
@@ -0,0 +1,10 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import type { TypedString } from "@/utils/typed";
+
+export type ConnectionName = TypedString<"ConnectionName">;
+
+// DuckDB engine is treated as the default engine
+// As it doesn't require passing an engine variable to the backend
+// Keep this in sync with the backend name
+export const DUCKDB_ENGINE = "__marimo_duckdb" as ConnectionName;
+export const INTERNAL_SQL_ENGINES = new Set([DUCKDB_ENGINE]);
diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsx
index 6ee049aa25..afdd807f96 100644
--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx
+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx
@@ -27,10 +27,8 @@ import { focusAndScrollCellOutputIntoView } from "../cells/scrollCellIntoView";
import type { CellData } from "../cells/types";
import { capabilitiesAtom } from "../config/capabilities";
import { useSetAppConfig } from "../config/config";
-import {
- type ConnectionName,
- useDataSourceActions,
-} from "../datasets/data-source-connections";
+import { useDataSourceActions } from "../datasets/data-source-connections";
+import type { ConnectionName } from "../datasets/engines";
import {
PreviewSQLTable,
PreviewSQLTableList,
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index 8c419c750e..b07381e5ec 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -1,113 +1,40 @@
{
+ /* Visit https://aka.ms/tsconfig to read more about this file */
"compilerOptions": {
- /* Visit https://aka.ms/tsconfig to read more about this file */
-
- /* Projects */
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
-
- /* Language and Environment */
- "target": "ES2019" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
- "lib": [
- "ESNext",
- "DOM"
- ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
- "jsx": "react-jsx" /* Specify what JSX code is generated. */,
- "experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */,
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
-
- /* Modules */
- "module": "ESNext" /* Specify what module code is generated. */,
- "rootDir": "src" /* Specify the root folder within your source files. */,
- "moduleResolution": "Bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
- "baseUrl": "src" /* Specify the base directory to resolve non-relative module names. */,
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
+ "target": "ES2019",
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
+ "module": "ESNext",
+ "skipLibCheck": true,
+ "esModuleInterop": true,
"types": [
"vite/client",
"@testing-library/jest-dom"
- ] /* Specify type package names to be included without being referenced in a source file. */,
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
- // "resolveJsonModule": true, /* Enable importing .json files. */
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
-
- /* JavaScript Support */
- "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
-
- /* Emit */
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
- "outDir": "build" /* Specify an output folder for all emitted files. */,
- // "removeComments": true, /* Disable emitting comments. */
- // "noEmit": true, /* Disable emitting files from a compilation. */
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
- // "newLine": "crlf", /* Set the newline character for emitting files. */
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
- // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
-
- /* Interop Constraints */
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
-
- /* Type Checking */
- "strict": true /* Enable all strict type-checking options. */,
- "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
- "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
- "strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
- "strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
- "strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
- "noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
- "useUnknownInCatchVariables": true /* Default catch clause variables as 'unknown' instead of 'any'. */,
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
- "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
- // "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
- // "noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
- "noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
- "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
- // "noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type. */,
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
-
- /* Completeness */
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
- "skipLibCheck": true /* Skip type checking all .d.ts files. */,
+ ],
+
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "verbatimModuleSyntax": true,
+ "moduleDetection": "force",
+ "noEmit": true,
+ "jsx": "react-jsx",
+
+ /* Linting */
+ "strict": true,
+ "noUnusedLocals": true,
+ "noFallthroughCasesInSwitch": true,
+ "noUncheckedSideEffectImports": true,
+ "noImplicitOverride": true,
+
+ /* Style */
"paths": {
- "@/*": ["./*"]
- }
+ "@/*": ["./src/*"]
+ },
+ "forceConsistentCasingInFileNames": true,
+ "useDefineForClassFields": true,
+ "experimentalDecorators": true
},
"include": ["src"]
}
+