Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(desktop): typecheck apps/mobile in CI against an error baseline (#83146)

Thomas Obermüller024a481e1c7f
diff --git a/products/desktop/AGENTS.md b/products/desktop/AGENTS.md
index 50a874c44b07..08cb2f10489b 100644
--- a/products/desktop/AGENTS.md
+++ b/products/desktop/AGENTS.md
@@ -219,6 +219,22 @@ await boot(container);
- `pnpm --filter <pkg> typecheck|test|build`: run a scoped task.
- `pnpm --filter code package|make`: package the Electron app.
- `node scripts/check-host-boundaries.mjs`: verify host boundary allowlist.
+- `node scripts/check-mobile-types.mjs`: typecheck `apps/mobile` against its error baseline.
+
+## Mobile Host Types
+
+`apps/mobile` typechecks against a baseline of pre-existing errors, not against zero.
+`pnpm typecheck` runs it like every other package; `scripts/check-mobile-types.mjs` fails only on errors absent from `scripts/mobile-type-baseline.json`.
+
+Metro strips types instead of checking them, so before this the mobile host was the one place a shared-package change could break without CI noticing — a new method on a `@posthog/platform` interface, a renamed `@posthog/core` export.
+
+After fixing baselined errors, shrink the baseline:
+
+```bash
+node scripts/check-mobile-types.mjs --prune
+```
+
+Do not use `--init` to baseline new errors.
## UI Components
diff --git a/products/desktop/apps/mobile/package.json b/products/desktop/apps/mobile/package.json
index f9b9b5030d5e..30cbb32eb51c 100644
--- a/products/desktop/apps/mobile/package.json
+++ b/products/desktop/apps/mobile/package.json
@@ -9,6 +9,7 @@
"ios": "expo run:ios",
"ios:device": "expo run:ios --device",
"web": "expo start --web",
+ "typecheck": "node ../../scripts/check-mobile-types.mjs",
"test": "vitest run",
"test:watch": "vitest",
"prebuild": "expo prebuild",
diff --git a/products/desktop/apps/mobile/react-native-web.d.ts b/products/desktop/apps/mobile/react-native-web.d.ts
new file mode 100644
index 000000000000..f700126b2e1b
--- /dev/null
+++ b/products/desktop/apps/mobile/react-native-web.d.ts
@@ -0,0 +1,5 @@
+// react-native-web ships no type declarations. Tests use it as the DOM stand-in
+// for react-native, so borrow that module's surface rather than widen to any.
+declare module "react-native-web" {
+ export * from "react-native";
+}
diff --git a/products/desktop/scripts/check-mobile-types.mjs b/products/desktop/scripts/check-mobile-types.mjs
new file mode 100644
index 000000000000..acaaf233320e
--- /dev/null
+++ b/products/desktop/scripts/check-mobile-types.mjs
@@ -0,0 +1,183 @@
+#!/usr/bin/env node
+import { spawnSync } from "node:child_process";
+import { existsSync, readFileSync, writeFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
+const BASELINE = join(ROOT, "scripts", "mobile-type-baseline.json");
+const MOBILE = join(ROOT, "apps", "mobile");
+
+const USAGE = `check-mobile-types — typecheck apps/mobile, failing only on errors that are not already baselined.
+
+ node scripts/check-mobile-types.mjs verify: fail on any error not in the baseline
+ node scripts/check-mobile-types.mjs --init (re)generate the baseline from current errors
+ node scripts/check-mobile-types.mjs --prune drop baseline entries that no longer error (after fixing)
+
+apps/mobile had no typecheck at all, so a breaking change to a shared package
+(a new method on a platform interface, a renamed export) only surfaced when
+someone opened the file. Metro strips types, so nothing else caught it. The
+baseline grandfathers the errors that already existed so that gap could be
+closed today; its length is the cleanup still owed. Goal: 0.`;
+
+const ERROR_LINE = /^(\S.*?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
+const ABSOLUTE_PATH = /\/\S*\/(node_modules\/\S*)/g;
+
+/**
+ * Some messages quote a resolved absolute path (TS7016 names the JS file it
+ * could not find types for). The path differs between a laptop and CI, so a
+ * baseline written on one machine would not match on the other.
+ */
+function normalizeMessage(message) {
+ return message.replaceAll(ROOT, "<desktop>").replace(ABSOLUTE_PATH, "$1");
+}
+
+/**
+ * Error identity is file + code + message, without line/column, so unrelated
+ * edits above an error don't churn the baseline. The cost: swapping one
+ * baselined error for an identical one elsewhere in the same file keeps the
+ * count level and passes. Keying on lines would trade that narrow hole for a
+ * baseline that needs rewriting on every edit, which is the worse deal.
+ */
+function runTsc() {
+ const result = spawnSync(
+ "pnpm",
+ ["exec", "tsc", "--noEmit", "--pretty", "false"],
+ {
+ cwd: MOBILE,
+ encoding: "utf8",
+ },
+ );
+ const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
+ const errors = {};
+ let parsed = 0;
+
+ for (const line of output.split("\n")) {
+ const match = ERROR_LINE.exec(line);
+ if (!match) continue;
+ const [, file, , , code, message] = match;
+ const key = `${code} ${normalizeMessage(message)}`;
+ errors[file] ??= {};
+ errors[file][key] = (errors[file][key] ?? 0) + 1;
+ parsed += 1;
+ }
+
+ // tsc exits non-zero for a broken config or a missing compiler too, and that
+ // must not read as "no errors found".
+ if (result.status !== 0 && parsed === 0) {
+ console.error(`\n✗ tsc failed without reporting type errors:\n\n${output}`);
+ process.exit(1);
+ }
+
+ return errors;
+}
+
+function loadBaseline() {
+ if (!existsSync(BASELINE)) return {};
+ return JSON.parse(readFileSync(BASELINE, "utf8")).files ?? {};
+}
+
+function saveBaseline(files) {
+ const sorted = Object.fromEntries(
+ Object.keys(files)
+ .filter((file) => Object.keys(files[file]).length)
+ .sort()
+ .map((file) => [
+ file,
+ Object.fromEntries(
+ Object.keys(files[file])
+ .sort()
+ .map((message) => [message, files[file][message]]),
+ ),
+ ]),
+ );
+ writeFileSync(
+ BASELINE,
+ `${JSON.stringify(
+ {
+ note: "Pre-existing apps/mobile type errors, counted per file and message. Remove entries as you fix them. Goal: empty.",
+ files: sorted,
+ },
+ null,
+ 2,
+ )}\n`,
+ );
+}
+
+function count(files) {
+ return Object.values(files).reduce(
+ (total, byKey) =>
+ total + Object.values(byKey).reduce((sum, n) => sum + n, 0),
+ 0,
+ );
+}
+
+const mode = process.argv[2];
+if (mode === "--help" || mode === "-h") {
+ console.log(USAGE);
+ process.exit(0);
+}
+
+const current = runTsc();
+const baseline = loadBaseline();
+
+if (mode === "--init") {
+ saveBaseline(current);
+ console.log(`Baseline written: ${count(current)} known error(s).`);
+ process.exit(0);
+}
+
+if (mode === "--prune") {
+ const kept = {};
+ for (const [file, byKey] of Object.entries(baseline)) {
+ for (const [key, allowed] of Object.entries(byKey)) {
+ const still = current[file]?.[key] ?? 0;
+ if (!still) continue;
+ kept[file] ??= {};
+ kept[file][key] = Math.min(allowed, still);
+ }
+ }
+ saveBaseline(kept);
+ console.log(
+ `Pruned. ${count(baseline) - count(kept)} fixed, ${count(kept)} remaining.`,
+ );
+ process.exit(0);
+}
+
+const fresh = [];
+let fixed = 0;
+
+for (const [file, byKey] of Object.entries(current)) {
+ for (const [key, seen] of Object.entries(byKey)) {
+ const allowed = baseline[file]?.[key] ?? 0;
+ if (seen > allowed) fresh.push({ file, key, extra: seen - allowed });
+ }
+}
+
+for (const [file, byKey] of Object.entries(baseline)) {
+ for (const [key, allowed] of Object.entries(byKey)) {
+ fixed += Math.max(0, allowed - (current[file]?.[key] ?? 0));
+ }
+}
+
+if (fixed) {
+ console.log(
+ `\n✓ ${fixed} baselined error(s) fixed since the baseline — run --prune to shrink it.`,
+ );
+}
+
+if (fresh.length) {
+ console.error(`\n✗ ${fresh.length} NEW type error(s) in apps/mobile:\n`);
+ for (const { file, key, extra } of fresh) {
+ console.error(` ${file}\n ${key}${extra > 1 ? ` (×${extra})` : ""}`);
+ }
+ console.error(
+ `\nFix them, or if this is a deliberate widening of an existing problem, justify it in review and rerun with --init.`,
+ );
+ process.exit(1);
+}
+
+console.log(
+ `\n✓ No new type errors. ${count(baseline)} baselined error(s) remaining. Goal: 0.`,
+);
+process.exit(0);
diff --git a/products/desktop/scripts/mobile-type-baseline.json b/products/desktop/scripts/mobile-type-baseline.json
new file mode 100644
index 000000000000..7ac42ce24ddc
--- /dev/null
+++ b/products/desktop/scripts/mobile-type-baseline.json
@@ -0,0 +1,125 @@
+{
+ "note": "Pre-existing apps/mobile type errors, counted per file and message. Remove entries as you fix them. Goal: empty.",
+ "files": {
+ "src/app/mcp-servers/add-custom.tsx": {
+ "TS2322 Type '\"none\"' is not assignable to type 'MCPAuthTypeEnum'.": 1,
+ "TS2345 Argument of type '\"none\"' is not assignable to parameter of type 'MCPAuthTypeEnum | (() => MCPAuthTypeEnum)'.": 1
+ },
+ "src/app/mcp-servers/installation/[id].tsx": {
+ "TS2559 Type 'McpServerInstallation' has no properties in common with type '{ transport_type?: string | null | undefined; }'.": 1
+ },
+ "src/app/mcp-servers/template/[id].tsx": {
+ "TS2559 Type 'MCPServerTemplate' has no properties in common with type '{ transport_type?: string | null | undefined; }'.": 1
+ },
+ "src/app/task/[id].tsx": {
+ "TS2322 Type 'TaskSession | undefined' is not assignable to type 'SessionActivityState | null | undefined'.": 1
+ },
+ "src/features/inbox/components/DiffBlock.tsx": {
+ "TS2305 Module '\"@posthog/core/inbox/activityLog\"' has no exported member 'parseDiffLines'.": 1,
+ "TS7006 Parameter 'i' implicitly has an 'any' type.": 1,
+ "TS7006 Parameter 'line' implicitly has an 'any' type.": 1
+ },
+ "src/features/mcp/components/McpAppHost.tsx": {
+ "TS2339 Property 'resource' does not exist on type 'NonNullable<NoInfer<TQueryFnData>>'.": 1,
+ "TS2339 Property 'serverName' does not exist on type '{ server: string; tool: string; }'.": 2,
+ "TS2339 Property 'tool' does not exist on type 'NonNullable<NoInfer<TQueryFnData>>'.": 1,
+ "TS2339 Property 'toolName' does not exist on type '{ server: string; tool: string; }'.": 2,
+ "TS2551 Property 'absoluteFillObject' does not exist on type 'typeof StyleSheet'. Did you mean 'absoluteFill'?": 1,
+ "TS2769 No overload matches this call.": 1
+ },
+ "src/features/mcp/components/McpServerRow.tsx": {
+ "TS2559 Type 'MCPServerTemplate' has no properties in common with type '{ transport_type?: string | null | undefined; }'.": 1,
+ "TS2559 Type 'McpServerInstallation' has no properties in common with type '{ transport_type?: string | null | undefined; }'.": 1
+ },
+ "src/features/mcp/hooks.ts": {
+ "TS2345 Argument of type 'InstallCustomMcpServerOptions' is not assignable to parameter of type '{ name: string; url: string; auth_type: MCPAuthTypeEnum; api_key?: string | undefined; description?: string | undefined; client_id?: string | undefined; client_secret?: string | undefined; install_source?: \"posthog\" | ... 1 more ... | undefined; posthog_code_callback_url?: string | undefined; } & McpGatewayInstallSh...'.": 1,
+ "TS2345 Argument of type 'InstallMcpTemplateOptions' is not assignable to parameter of type '{ template_id: string; api_key?: string | undefined; install_source?: \"posthog\" | \"posthog-code\" | undefined; posthog_code_callback_url?: string | undefined; } & McpGatewayInstallSharingOptions'.": 1,
+ "TS2345 Argument of type '{ installation_id: string; install_source?: \"posthog\" | \"posthog-code\" | \"posthog-mobile\" | undefined; posthog_code_callback_url?: string | undefined; }' is not assignable to parameter of type '{ installation_id: string; install_source?: \"posthog\" | \"posthog-code\" | undefined; posthog_code_callback_url?: string | undefined; }'.": 1
+ },
+ "src/features/mcp/sandbox/useMcpUiResource.ts": {
+ "TS2769 No overload matches this call.": 1
+ },
+ "src/features/navigation/components/NavDrawer.tsx": {
+ "TS2551 Property 'absoluteFillObject' does not exist on type 'typeof StyleSheet'. Did you mean 'absoluteFill'?": 2
+ },
+ "src/features/tasks/components/AutomationDetail.tsx": {
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'TaskAutomation' locally, but it is not exported.": 1
+ },
+ "src/features/tasks/components/AutomationForm.test.tsx": {
+ "TS2339 Property 'root' does not exist on type 'never'.": 7,
+ "TS7006 Parameter 'node' implicitly has an 'any' type.": 2
+ },
+ "src/features/tasks/components/AutomationForm.tsx": {
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'CreateTaskAutomationOptions' locally, but it is not exported.": 1
+ },
+ "src/features/tasks/components/AutomationItem.tsx": {
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'TaskAutomation' locally, but it is not exported.": 1
+ },
+ "src/features/tasks/components/AutomationList.tsx": {
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'TaskAutomation' locally, but it is not exported.": 1
+ },
+ "src/features/tasks/components/AutomationSkillCard.test.tsx": {
+ "TS2339 Property 'root' does not exist on type 'never'.": 5,
+ "TS7006 Parameter 'node' implicitly has an 'any' type.": 5
+ },
+ "src/features/tasks/components/AutomationSkillCard.tsx": {
+ "TS2305 Module '\"@posthog/api-client\"' has no exported member 'LlmSkillListItem'.": 1
+ },
+ "src/features/tasks/components/AutomationSkillChooser.test.tsx": {
+ "TS2339 Property 'root' does not exist on type 'never'.": 8,
+ "TS7006 Parameter 'node' implicitly has an 'any' type.": 4
+ },
+ "src/features/tasks/components/AutomationStatusBadge.test.tsx": {
+ "TS2339 Property 'toJSON' does not exist on type 'never'.": 2
+ },
+ "src/features/tasks/components/CreateAutomationScreen.test.tsx": {
+ "TS2339 Property 'root' does not exist on type 'never'.": 5,
+ "TS7006 Parameter 'node' implicitly has an 'any' type.": 2
+ },
+ "src/features/tasks/components/PlanApprovalCard.test.tsx": {
+ "TS2339 Property 'root' does not exist on type 'never'.": 2
+ },
+ "src/features/tasks/components/PlanApprovalCard.tsx": {
+ "TS2345 Argument of type 'CloudPermissionOption' is not assignable to parameter of type 'PermissionOption'.": 3
+ },
+ "src/features/tasks/components/TaskSessionView.test.tsx": {
+ "TS18047 'renderer' is possibly 'null'.": 1,
+ "TS2339 Property 'root' does not exist on type 'never'.": 1
+ },
+ "src/features/tasks/components/TaskSessionView.tsx": {
+ "TS2305 Module '\"../types\"' has no exported member 'SessionEvent'.": 1,
+ "TS2305 Module '\"../types\"' has no exported member 'SessionNotification'.": 1
+ },
+ "src/features/tasks/composer/DotBackground.tsx": {
+ "TS2551 Property 'absoluteFillObject' does not exist on type 'typeof StyleSheet'. Did you mean 'absoluteFill'?": 1
+ },
+ "src/features/tasks/hooks/useAutomations.ts": {
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'CreateTaskAutomationOptions' locally, but it is not exported.": 1,
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'TaskAutomation' locally, but it is not exported.": 1,
+ "TS2459 Module '\"@posthog/api-client/posthog-client\"' declares 'UpdateTaskAutomationOptions' locally, but it is not exported.": 1
+ },
+ "src/features/tasks/hooks/useCloudAttachmentPreview.ts": {
+ "TS2305 Module '\"../types\"' has no exported member 'CloudArtifactRef'.": 1
+ },
+ "src/features/tasks/hooks/useIntegrations.ts": {
+ "TS2345 Argument of type '{ [key: string]: unknown; kind: string; id: string | number; }[]' is not assignable to parameter of type 'Integration[]'.": 1,
+ "TS2345 Argument of type '{ data: { integrationId: string | number; repos: any; }; isPending: boolean; isError: false; isRefetching: boolean; }[]' is not assignable to parameter of type 'readonly RepositoryQueryResult<TeamRepositoriesResult>[]'.": 1,
+ "TS7015 Element implicitly has an 'any' type because index expression is not of type 'number'.": 2
+ },
+ "src/features/tasks/stores/taskSessionStore.ts": {
+ "TS2305 Module '\"../types\"' has no exported member 'SessionEvent'.": 1,
+ "TS2305 Module '\"../types\"' has no exported member 'SessionNotification'.": 1
+ },
+ "src/features/tasks/utils/promptAttachments.test.ts": {
+ "TS2305 Module '\"../types\"' has no exported member 'SessionEvent'.": 1
+ },
+ "src/features/tasks/utils/promptAttachments.ts": {
+ "TS2305 Module '\"../types\"' has no exported member 'CloudArtifactRef'.": 1,
+ "TS2305 Module '\"../types\"' has no exported member 'SessionEvent'.": 1,
+ "TS2353 Object literal may only specify known properties, and 'cloudArtifact' does not exist in type 'SessionNotificationAttachment'.": 1
+ },
+ "src/features/tasks/utils/repositorySelection.test.ts": {
+ "TS2322 Type '{ installation_id: string; account: { name: string; }; } | { installation_id: string; }' is not assignable to type 'UserGithubIntegration'.": 1
+ }
+ }
+}