Skip to content

Spec: page TypeScript #236

Closed
17 of 17 issues completed
Closed

Description

@jtklein-agents

Decisions come from the wayfinder map "Map: page to TypeScript" (#225). Its child tickets #226 to #233 hold the detail; research notes sit on the research/page-ts-inventory and research/mobx7-typescript branches and the prototype on prototype/option-typing, none of them merged.

Feature branch

Child tickets open pull requests against spec/236-page-typescript (cut from master). Do not target master for these children.

Problem Statement

The main process is TypeScript, but the Page is not. The panels, the Page store, the page helpers, the preload and the three alignment parsers are still JavaScript: about 8,000 lines in 40 files. A maintainer changing the Page store or a panel gets no help from the typechecker. All 26 diagnostics left in the typecheck baseline sit in those files, so the baseline shelters old errors instead of being empty. The Page reaches the Renderer bridge through an untyped cast, so a mismatch between what the Page sends and what main expects is found only at runtime. And "no implicit any" on the TypeScript that already exists is held by review alone.

Solution

Convert every production file of the Page, the preload and the three alignment parsers to TypeScript, leaf by leaf, on one feature branch. Each file keeps its shape and gains explicit types. A CI check requires zero implicit any in every TypeScript file, and lint bans a written any. The Renderer bridge gets one declared type that the preload is checked against and the Page reads from window with no cast. The typecheck baseline ends empty. The app behaves exactly as before: a bug that typing exposes becomes its own issue, not a fix inside a leaf.

User Stories

  1. As a maintainer, I want every production file of the Page in TypeScript, so that the typechecker covers the whole Shell.
  2. As a maintainer, I want the Page store typed, so that a wrong member name or argument is caught before the app runs.
  3. As a maintainer, I want every panel to have a typed props interface, so that a call site that omits or misnames a prop fails the typecheck.
  4. As a maintainer, I want the preload in TypeScript and checked against the Renderer bridge type, so that the preload cannot drift from what the Page expects.
  5. As a page developer, I want to read window.rendererBridge with no cast, so that every bridge call is checked.
  6. As a page developer, I want the payloads that cross the Renderer bridge typed once, in main, so that the Page and main cannot disagree about a payload's shape.
  7. As a page developer, I want the Page to import those crossing types as types only, so that the Page still loads no main-process code and no channel strings.
  8. As a maintainer, I want the three alignment parsers in TypeScript, so that the Page and main share typed parse results.
  9. As a maintainer, I want CI to fail on any implicit any in a TypeScript file, so that "full typing" is checked by a machine and not by review.
  10. As a maintainer, I want that check to need no hand-kept list of files, so that a renamed file is covered the moment it is renamed.
  11. As a maintainer, I want no allowlist in that check, so that it cannot shelter a slip.
  12. As a maintainer, I want lint to reject a written any in TypeScript, so that the implicit-any check is not bypassed by typing the word.
  13. As a maintainer, I want one lint rule set for all TypeScript under the source tree, so that Page files meet the same bar as main-process files.
  14. As a maintainer, I want the compiler's strict and noImplicitAny settings left off, so that the remaining JavaScript (tests, settings) still typechecks as it does today.
  15. As a maintainer, I want the typecheck baseline to end empty, so that every remaining diagnostic is a new one.
  16. As a maintainer, I want the baseline check to pass on an empty baseline, so that the mechanism stays for future use without a placeholder line.
  17. As an agent implementer, I want each leaf to delete the baseline lines it clears, so that progress shows in CI.
  18. As an agent implementer, I want each leaf to be whole files grouped by family, so that no file is ever half converted.
  19. As an agent implementer, I want only a few fixed ordering edges between leaves, so that most leaves can land in parallel.
  20. As an agent implementer, I want the option base converted before its subclasses, so that the subclasses inherit a typed constructor and value.
  21. As an agent implementer, I want one generic option base over its value and its owner, so that each option subclass states its value type once.
  22. As an agent implementer, I want a rule that a subclass never redeclares a base field, so that no option value is reset to undefined after construction.
  23. As an agent implementer, I want an option's owner and a panel's store-object props typed by a small module-local interface, so that a leaf does not have to wait for the store class it reads from.
  24. As an agent implementer, I want the MobX annotation maps left as they are, so that typing changes no observable behaviour.
  25. As a maintainer, I want propTypes blocks removed when a panel gets typed props, so that there is one description of a panel's props and no dead code.
  26. As a page developer, I want each prop's required or optional status carried over exactly, so that no panel's contract loosens or tightens.
  27. As a maintainer, I want the direct prop-types dependency removed once nothing imports it, so that the manifest lists only what the Page uses.
  28. As a maintainer, I want types for lodash and d3-array installed as dev dependencies, so that their callers are checked without hand-written declarations.
  29. As a user of the app, I want it to behave exactly as before the conversion, so that a typing effort changes nothing I can see.
  30. As a maintainer, I want a bug that typing exposes filed as its own issue, so that a behaviour change is reviewed by itself.
  31. As an agent implementer, I want a fixed rule for meeting such a bug (keep the behaviour, widen the type or add a reasoned @ts-expect-error, file an issue, carry on), so that a leaf never stalls on it.
  32. As a maintainer, I want each @ts-expect-error to carry its reason, so that it fails by itself, with context, once the bug is fixed.
  33. As a reviewer, I want each bug issue linked from the pull request of the leaf that met it, so that I can tell an accommodation from a shortcut.
  34. As a maintainer, I want the tests and the Jest setup files to stay JavaScript, so that the conversion does not rewrite the test tree.
  35. As a maintainer, I want the existing Jest suites to keep passing unchanged in behaviour, so that they prove the conversion kept runtime behaviour.
  36. As a maintainer, I want every test, script and config entry that opens a converted file by fixed path updated in the leaf that renames it, so that no check silently stops reading its file.
  37. As a developer, I want yarn build and yarn start to keep working after each leaf, so that the feature branch always launches.
  38. As a maintainer, I want the build config's JSX-in-.js handling removed once no production .js file holds JSX, so that the config says what the code is.
  39. As a maintainer, I want the unused decorator-based store coverage script deleted, so that no dead tooling is left pointing at files that moved.
  40. As a reviewer, I want the tracker conventions and coding standards updated where a leaf changes a rule (the bridge cast rule, the Checks section, the crossing-types exception), so that later tickets inherit the new rules.
  41. As an upstream maintainer, I want the whole effort to arrive as one pull request from the feature branch, so that the Page is never upstream in a half-converted state.

Implementation Decisions

Scope and bar

  • In scope: the production files of the Page (panels, Page store, page helpers, page entry), the preload, and the three alignment parsers in the shared folder (FASTA, PHYLIP, alignment typecheck). 40 files, 14 of them holding JSX.
  • Done bar per file: renamed to .ts or .tsx, shape kept, explicit types added, zero diagnostics with or without --noImplicitAny, its baseline lines gone.
  • Types only. No behaviour change, no refactor, no file split or partial conversion.
  • tsconfig.json is unchanged: strict and noImplicitAny stay off, allowJs stays on.
  • Import specifiers stay extensionless.

The no-implicit-any check

  • Rule: every .ts and .tsx file under the source tree has zero diagnostics under --noImplicitAny. The extension is the ratchet; a JavaScript file is exempt until its leaf renames it.
  • It is a second tsc pass inside the existing yarn typecheck:baseline command. One command, one CI step, no allowlist.
  • The two existing slips, both in the main-process model-selection module and both caused by parse-filepath shipping no types, are fixed by a types-only module declaration in the leaf that adds the check.
  • Lint: @typescript-eslint/no-explicit-any applies to all TypeScript. The "full typing" rule block (explicit module boundary types, annotated catch) widens from the main process and shared folder to all TypeScript under the source tree. The four existing violations in the already-TypeScript page components are fixed in the same leaf.
  • The baseline script learns to pass when the baseline file is empty. The mechanism stays.

Renderer bridge

  • One declared RendererBridge interface in a types-only module in the shared folder. It is declared, not derived from the preload, because the ipc invoke call types every result as any.
  • The preload's object is checked against it with satisfies.
  • A global Window declaration adds rendererBridge, so a Page file reads it with no cast. This replaces the rule that a TypeScript Page file casts window through unknown. The store-entry leaf adds the deliberate store global to the same declaration.
  • Call sites keep their shape: the bridge is still read from window inside each method, not once at module load, because tests replace it between cases.
  • Crossing payloads are typed once, in main. Main exports the types it already declares beside its handlers, and the bridge type module imports them type-only. This is additive exports only and an exception to "inject types stay module-local". Event payloads have no named type in main today; the leaf that first needs one adds it in main.
  • The interface grows leaf by leaf. The bridge leaf names every member with the types that are free; each later leaf tightens the members its files call.
  • Still-JavaScript Page files keep their any cast until their own leaf.

Page store

  • Option base, from the prototype:

    class Option<Value = unknown, Owner = unknown> {
      run: Owner;
      value: Value; // bare field, annotation map unchanged
      // error: ValidationError | boolean | null
    }
    // a subclass: extends Option<string[], OptionRun>

    description and hoverInfo become optional constructor parameters; the options argument gets an OptionSettings interface. No caller changes.

  • The owner is a small module-local interface holding only what that leaf reads from its owner: one per leaf file, not per class. The option base imports no store type. These interfaces stay after Run converts; there is no later sweep.

  • A subclass never redeclares a base field to narrow its type. Class fields are defined, so a redeclaration would reset the field after super(). The type parameter does the narrowing.

  • MobX annotation maps are unchanged and need nothing extra from TypeScript: the store has no flow, no non-public members and no options argument.

Panels

  • A panel that becomes .tsx gets an exported <Name>Props interface; its propTypes block and prop-types import are deleted in the same leaf (React 19 ignores them).
  • isRequired becomes a required member; every other prop is optional.
  • Store-object props (run, alignment, tree, citation, store) are typed by a small module-local interface, as the existing option components do. No type import of the store class.
  • The direct prop-types dependency line leaves the manifest in whichever leaf deletes the last import. The lock stanza stays; other packages still depend on it.

Untyped packages

  • @types/lodash and @types/d3-array as dev dependencies, each added by the first leaf that converts an importer (lodash: final alignment or Run; d3-array: run options).

Bugs typing exposes

  • Definition: a diagnostic that cannot be cleared without changing what the code does at runtime.
  • A leaf keeps the behaviour, makes the file compile with the narrowest accommodation (a widened type, else a @ts-expect-error with a one-line reason), files one issue per bug outside this spec, links it from its pull request, and carries on.
  • Two are known and already filed: Clear console icon passes title, which the MUI icon does not accept #234 (the clear-console icon's title prop, met by the app shell leaf with @ts-expect-error) and MultistateNumber.error returns a boolean, so the option always reports an error #235 (MultistateNumber.error returns a boolean, met by the alignment-options leaf; the option base's widened error covers it).
  • Not bugs, cleared by types alone: the store global on window, the two error-dialog call sites that omit optional props, and the JSDoc yup name in the option base.

Leaves

Seventeen leaves. A leaf is one pull request of whole files.

# Leaf Holds
1 No-implicit-any check and lint rules the baseline script (second pass, empty baseline passes), the lint config, the parse-filepath declaration, four lint fixes
2 Renderer bridge type and preload the new bridge type module, the preload, the Window declaration, the cast removed from the page bootstrap, type exports in main
3 Option base the option base class
4 Alignment parsers FASTA parser, PHYLIP parser, alignment typecheck
5 Page helpers paths, report, GitHub issue, promised computed, host
6 Store bases store base, input file, ASTRAL tree, config, app store, citation
7 Alignment and part options alignment options, part options
8 Run options run options
9 Partition family final partition, partition
10 Final alignment final alignment
11 Alignment alignment
12 Run run (one leaf on its own)
13 Run list and store entry run list, store entry
14 Input-file cards alignment card, ASTRAL tree card, tree card, partition file card, partition editor
15 Run panels input, model, output, RAxML, console, citation modal
16 App shell error dialog, app, page entry
17 Close-out build config leftovers, docs, the store coverage script

Fixed order: leaf 1 first, leaf 2 second; leaf 3 before leaves 7 and 8; leaf 16 after every other conversion leaf; leaf 17 last. Everything else may land in any order or in parallel. Parallel leaves collide in the baseline file and the bridge type module; small merge conflicts there are accepted.

Per-leaf consequences:

  • The page-Node-imports test reads the alignment store, the run store and the page entry by fixed path; leaves 11, 12 and 16 each update their line.
  • The last four baseline lines go with leaf 13 (store entry) and leaf 16 (app).
  • Leaf 1 amends the Checks section of the tracker conventions and the lint comment that names the main-process spec.
  • Leaf 2 updates the Renderer bridge cast rule in the tracker conventions and notes the crossing-types exception under TypeScript renames in the coding standards.
  • Leaf 17 removes the build config's JSX-in-.js handling, deletes the decorator-based store coverage script (the store has no decorators and nothing runs it), makes any doc edits leaves 1 and 2 did not, and updates any TODO.md note.

Testing Decisions

  • A good test here checks external behaviour: the existing Jest suites exercise the Page store, the panels' render and the bridge through their public surface. They stay JavaScript and must keep passing with no change other than a fixed path that moved. A leaf adds no test whose only purpose is to prove a file extension.
  • Seam 1, typing: yarn typecheck:baseline. Both passes: known diagnostics match the baseline, and no TypeScript file has an implicit any. Done for a leaf means its files' baseline lines are gone; done for the spec means the baseline is empty.
  • Seam 2, behaviour: the existing Jest suites (yarn react-test): the store tests, the page render test, the preload launch test and its proof files, the page-Node-imports test.
  • Seam 3, lint: yarn lint with the widened rule set.
  • Seam 4, build: yarn build still emits the main, preload and page output; the e2e suite runs on the built Shell as it does today.
  • New test code only in leaf 1: the baseline script's second pass and its empty-baseline case, beside the existing baseline helper test. That is the only new logic in the spec.
  • Jest stand-ins for the bridge stay untyped JavaScript.
  • Prior art: the main-process TypeScript spec (Spec: main-process TypeScript #67) and its landed leaves; the baseline helper test; the already-TypeScript option components for module-local prop interfaces.

Out of Scope

Further Notes

  • Glossary: Page, Page store, Renderer bridge, Shell.
  • Measured on master at b0d2729 (MobX 7.1.7, TypeScript 5.9.3, React 19.3.1): plain tsc reports 26 diagnostics, all in scope; --noImplicitAny adds 414 in scope, 267 of them in seven files. Typing the option base alone clears 22 of the 26.
  • Neither known bug was confirmed by running the app; both verdicts come from reading the code.
  • Not verified by the map: what the Vite renderer build emits for a type-only class field, and mobx-utils typings against MobX 7. The Jest transform was verified to keep the bare value field.
  • The tracker conventions and coding standards are kept on the maintainer's clone only, so a leaf's edits to them do not appear in its pull request diff.
  • Next: /to-tickets for the 17 leaves, then /implement per ticket.

Sub-issues

Sub-issues

17 of 17 Issues completed
Loading 17 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions