Skip to content

Type-check the root project (src/) and add it to CI #300

Open

Description

@GoDiao

Problem

The root project (src/: the CLI and the server) is never type-checked. CI type-checks only desktop/ (bun run lint in .github/workflows/ci.yml), and Bun runs TypeScript without checking types, so tests pass regardless.

Running tsc --noEmit at the root reports several thousand errors. New code in src/ therefore has no type gate: in #299 the only way to check a change was to diff the error list before and after by hand.

Where the errors come from

Measured in a clean worktree on 2893b320 with the root tsconfig.json (TypeScript 6.0.3, --ignoreDeprecations 6.0): 6,439 errors. An earlier count in this issue (about 6,700, on 89678866 in a checkout with more directories) used a different scope.

Cause Errors Notes
React Compiler output committed as source about 2,500 remain after everything below is fixed 390 .tsx files under src/ import react/compiler-runtime. Parameter types were dropped when they were compiled, for example export function useAppState(selector) { in src/state/AppState.tsx. This is the terminal UI. It is the main source of TS7006 (implicit any parameter)
No React types in the root project 1,656 × TS7016 package.json depends on react but had no @types/react. An earlier version of this issue attributed most TS7006 errors to this; measured, adding the types removes only 286 of them
Type files that are generated stubs about 900 at the import sites 167 files under src/ carry @generated stub from scan-missing-imports (written by desktop/scripts/scan-missing-imports.ts). 31 of them are used only as type sources, src/types/message.ts being the largest (imported by 201 files). 100 stand in for runtime modules that do not exist in this repository. Four more hand-written empty files under src/entrypoints/sdk/ have the same effect
Missing declarations about 560 react/compiler-runtime exports no c in @types/react; the global MACRO set in preload.ts; .md text modules; ink's custom JSX elements
The root tsconfig.json has no include 210 It also checked desktop/, vendor/, website/ and experiments/, which have their own configs. In a checkout with refs/ or worktrees under .claude/worktrees, the check ran out of memory
Other missing @types/* packages 37 ws, semver, qrcode, react-reconciler, shell-quote, picomatch, turndown, proper-lockfile, stack-utils
Other about 1,000 Type mismatches in .ts files and hand-written .tsx files. Not reviewed one by one

A further finding: 541 .tsx files, including all 390 compiled ones, end with an inline source map that contains the original source with its type annotations.

Plan

  1. Limit the root tsconfig.json to the code it owns (src/, scripts/, stubs/, the two preload files), drop the deprecated baseUrl, and add a typecheck script.
  2. Add @types/react and the other missing @types/* packages.
  3. Add the missing declarations and replace the type-only stub files with real types. Every type is taken from evidence in the repository: Zod schemas, constructor functions, literal usage, or types from dependencies.
  4. Compiled React Compiler output: the terminal UI is not under active development, so these files are marked // @ts-nocheck and left as they are. Exports that checked code calls get their signatures back from the inline source maps.
  5. Go through what is left in .ts and hand-written .tsx files.
  6. Once the count is zero, add the root type check to CI.

Each step reports the error count before and after.

Progress

Steps 1 to 3 are done on a local branch and not yet in a PR: 6,439 → 6,219 (scope) → 5,210 (@types/react) → 3,499 (declarations and 29 type files, no change to runtime code). Six type names had no evidence in the repository and are still missing.

Not covered by any type check

desktop/sidecars/dreamcoder-sidecar.ts, desktop/scripts/*.ts and experiments/. desktop/tsconfig.json includes only desktop/src, and desktop/electron/tsconfig.json only desktop/electron.

Found along the way

  • Plugin reload without an active session leaves custom agents out of the count #301: plugin reload without an active session leaves custom agents out of the count.
  • src/buddy/observer.ts:32-38 reads role and content at the top level of internal messages, which have type and message.content instead, so the terminal UI companion never speaks. From reading the code, not from running it.
  • src/cli/print.ts handles 11 control request subtypes (for example side_question, generate_session_title, remote_control) that are missing from the request union in src/entrypoints/sdk/controlSchemas.ts. Runtime is unaffected because these schemas are not used for validation.
  • src/keybindings/defaultBindings.ts:196,271 use the contexts Scroll and MessageActions, which are not in the list in src/keybindings/schema.ts:12-32.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ciCI / build / releaseenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions