From 8106880855ee0bb4b5bbca8827cfe97fe99558b8 Mon Sep 17 00:00:00 2001 From: KRATOS <84986124+gnanam1990@users.noreply.github.com> Date: Tue, 28 Apr 2026 15:14:26 +0530 Subject: [PATCH] fix(typecheck): make `bun run typecheck` actionable on main (#473) (#938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #473 reported that `bun run typecheck` fails on main with ~4400 errors due to repo-foundation drift, masking branch-specific regressions. Per kevincodex1's guidance ("lets narrow the typecheck scope for now and then we expand step by step") this PR addresses the foundational root causes and brings the error count down 60% so the gate is actionable for branch reviews. Changes: - tsconfig.json: bump target to ES2023 + add lib ["ES2023", "DOM"] so Array.findLast / findLastIndex resolve (kills 41 TS2550 errors). Add `noEmit: true` for typecheck-only mode and `allowImportingTsExtensions: true` (kills 40 TS5097 errors). Set `noImplicitAny: false` because cleaning up TSX-component implicit any is explicitly out of scope per the issue. - src/global.d.ts: ambient declaration for the build-time MACRO global injected by scripts/build.ts via Bun's `define` option (kills 9 TS2304 'Cannot find name MACRO' errors). - src/types/{message,utils,tools}.ts: stubs for the highest-impact missing modules from the partial source snapshot (~21 importers for message alone). Document the snapshot caveat at the top of each stub and reference issue #473 so future readers know they're placeholders. - src/entrypoints/sdk/controlTypes.ts and src/constants/querySource.ts: similar one-file stubs unblocking 18 + 19 importers respectively. - src/entrypoints/agentSdkTypes.ts: append `any`-typed aliases for ~70 SDK names that callers expect on the public surface but that live in stubbed sub-files (PermissionMode, SDKCompactBoundaryMessage, HookEvent, ModelUsage, ModelInfo, etc. — exactly the list from auriti's bug-report enumeration). Verified locally on Linux: - baseline `bunx tsc --noEmit` on stashed main: 4434 errors - with PR applied: 1782 errors (60% drop) - `bun run build`: passes (v0.7.0) - `bun test`: 1632 pass; the 4 remaining failures (StartupScreen, thinking) reproduce on main and are unrelated. - TS2550 (lib): 41 → 0 - TS5097 (.ts imports): 40 → 0 - TS2304 'MACRO': 9 → 0 - TS2307 missing modules: 587 → 325 Remaining errors are localized to specific stubbed modules and can be addressed in smaller follow-up issues, matching the issue's "Definition of done" criterion. --- src/constants/querySource.ts | 7 +++ src/entrypoints/agentSdkTypes.ts | 83 +++++++++++++++++++++++++++-- src/entrypoints/sdk/controlTypes.ts | 10 ++++ src/global.d.ts | 16 ++++++ src/types/message.ts | 25 +++++++++ src/types/tools.ts | 7 +++ src/types/utils.ts | 15 ++++++ tsconfig.json | 6 ++- 8 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 src/constants/querySource.ts create mode 100644 src/entrypoints/sdk/controlTypes.ts create mode 100644 src/global.d.ts create mode 100644 src/types/message.ts create mode 100644 src/types/tools.ts create mode 100644 src/types/utils.ts diff --git a/src/constants/querySource.ts b/src/constants/querySource.ts new file mode 100644 index 00000000..865c3a8d --- /dev/null +++ b/src/constants/querySource.ts @@ -0,0 +1,7 @@ +/** + * Stub — query source enum not included in source snapshot. See + * src/types/message.ts for the same scoping caveat (issue #473). + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type QuerySource = any diff --git a/src/entrypoints/agentSdkTypes.ts b/src/entrypoints/agentSdkTypes.ts index 1389113e..d0dc6feb 100644 --- a/src/entrypoints/agentSdkTypes.ts +++ b/src/entrypoints/agentSdkTypes.ts @@ -442,7 +442,84 @@ export async function connectRemoteControl( throw new Error('not implemented') } -// add exit reason types for removing the error within gracefulShutdown file +// add exit reason types for removing the error within gracefulShutdown file export type ExitReason = { - -} \ No newline at end of file + +} + +// ============================================================================ +// Stub re-exports — types not included in source snapshot. +// +// The upstream Anthropic SDK defines these in sub-files (sdk/coreTypes, +// sdk/runtimeTypes, sdk/controlTypes, sdk/toolTypes) that are stubbed +// in this open repo. Until the real definitions are restored, alias the +// names to `any` so callers can resolve their imports and `tsc` becomes +// actionable. See issue #473 for the typecheck-foundation effort. +// ============================================================================ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type AnyZodRawShape = any +export type ApiKeySource = any +export type AsyncHookJSONOutput = any +export type ConfigChangeHookInput = any +export type CwdChangedHookInput = any +export type ElicitationHookInput = any +export type ElicitationResultHookInput = any +export type FileChangedHookInput = any +export type ForkSessionOptions = any +export type ForkSessionResult = any +export type GetSessionInfoOptions = any +export type GetSessionMessagesOptions = any +export type HookEvent = any +export type HookInput = any +export type HookJSONOutput = any +export type InferShape<_T> = any +export type InstructionsLoadedHookInput = any +export type InternalOptions = any +export type InternalQuery = any +export type ListSessionsOptions = any +export type McpSdkServerConfigWithInstance = any +export type McpServerConfigForProcessTransport = any +export type McpServerStatus = any +export type ModelInfo = any +export type ModelUsage = any +export type NotificationHookInput = any +export type Options = any +export type PermissionDeniedHookInput = any +export type PermissionMode = any +export type PermissionRequestHookInput = any +export type PermissionResult = any +export type PermissionUpdate = any +export type PostCompactHookInput = any +export type PostToolUseFailureHookInput = any +export type PostToolUseHookInput = any +export type PreCompactHookInput = any +export type PreToolUseHookInput = any +export type Query = any +export type RewindFilesResult = any +export type SDKAssistantMessage = any +export type SDKAssistantMessageError = any +export type SDKCompactBoundaryMessage = any +export type SdkMcpToolDefinition = any +export type SDKPartialAssistantMessage = any +export type SDKPermissionDenial = any +export type SDKRateLimitInfo = any +export type SDKStatus = any +export type SDKStatusMessage = any +export type SDKSystemMessage = any +export type SDKToolProgressMessage = any +export type SDKUserMessageReplay = any +export type SessionEndHookInput = any +export type SessionMessage = any +export type SessionMutationOptions = any +export type SessionStartHookInput = any +export type SetupHookInput = any +export type StopFailureHookInput = any +export type StopHookInput = any +export type SubagentStartHookInput = any +export type SubagentStopHookInput = any +export type SyncHookJSONOutput = any +export type TaskCompletedHookInput = any +export type TaskCreatedHookInput = any +export type TeammateIdleHookInput = any +export type UserPromptSubmitHookInput = any \ No newline at end of file diff --git a/src/entrypoints/sdk/controlTypes.ts b/src/entrypoints/sdk/controlTypes.ts new file mode 100644 index 00000000..3077cc42 --- /dev/null +++ b/src/entrypoints/sdk/controlTypes.ts @@ -0,0 +1,10 @@ +/** + * Stub — control protocol types not included in source snapshot. See + * src/types/message.ts for the same scoping caveat (issue #473). + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type SDKControlRequest = any +export type SDKControlResponse = any +export type SDKControlPermissionRequest = any +export type StdoutMessage = any diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 00000000..2d2aaaf1 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,16 @@ +/** + * Build-time globals replaced by the bundler at build time. + * + * `scripts/build.ts` substitutes these via Bun's `define` option, so at + * runtime the references are inlined as string literals. This declaration + * exists only to make `tsc --noEmit` aware of them — without it, every + * `MACRO.*` access fires TS2304 "Cannot find name 'MACRO'". + */ +declare const MACRO: { + VERSION: string + DISPLAY_VERSION: string + BUILD_TIME: string + ISSUES_EXPLAINER: string + PACKAGE_URL: string + NATIVE_PACKAGE_URL: string | undefined +} diff --git a/src/types/message.ts b/src/types/message.ts new file mode 100644 index 00000000..2d7f53c3 --- /dev/null +++ b/src/types/message.ts @@ -0,0 +1,25 @@ +/** + * Stub — message type definitions not included in source snapshot. + * + * The upstream Anthropic source defines a rich Message discriminated union + * with structured Content blocks, role tags, tool_use payloads, and so on. + * That file is not mirrored to this open snapshot. This stub exists so + * `tsc --noEmit` can resolve `import { Message, ... } from 'src/types/message'` + * across the ~21 callers without fixing every transitive type the call + * sites use. + * + * Once the real definitions are restored upstream-side or reconstructed + * from runtime usage, replace these `any` aliases with proper types and + * delete this comment. See issue #473 for the typecheck-foundation effort. + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type Message = any +export type AssistantMessage = any +export type UserMessage = any +export type SystemMessage = any +export type SystemAPIErrorMessage = any +export type AttachmentMessage = any +export type ProgressMessage = any +export type HookResultMessage = any +export type NormalizedUserMessage = any diff --git a/src/types/tools.ts b/src/types/tools.ts new file mode 100644 index 00000000..1b07cc4c --- /dev/null +++ b/src/types/tools.ts @@ -0,0 +1,7 @@ +/** + * Stub — tool type definitions not included in source snapshot. See + * src/types/message.ts for the same scoping caveat (issue #473). + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type ShellProgress = any diff --git a/src/types/utils.ts b/src/types/utils.ts new file mode 100644 index 00000000..28965d47 --- /dev/null +++ b/src/types/utils.ts @@ -0,0 +1,15 @@ +/** + * Stub — utility type definitions not included in source snapshot. See + * src/types/message.ts for the same scoping caveat (issue #473). + */ + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export type DeepImmutable = T extends any[] + ? readonly DeepImmutable[] + : T extends object + ? { readonly [K in keyof T]: DeepImmutable } + : T + +export type Permutations = T extends T + ? T | `${T}${Permutations>}` + : never diff --git a/tsconfig.json b/tsconfig.json index ba7ed88a..eb9ed65a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,14 @@ { "compilerOptions": { - "target": "ES2022", + "target": "ES2023", + "lib": ["ES2023", "DOM"], "module": "ESNext", "moduleResolution": "bundler", "jsx": "react-jsx", "strict": true, + "noImplicitAny": false, + "noEmit": true, + "allowImportingTsExtensions": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true,