Skip to content

Prototype the typing pattern on Option and two subclasses #229

Closed

Description

@jtklein-agents

Question

What do the option base and two subclasses (one from the run options, one from the alignment options) look like as TypeScript: the generic over the value type, the constructor signature behind the 21 "Expected 5-6 arguments" baseline lines, and the annotation map? Is that pattern acceptable for the whole Option family?

Activity

  1. added
    wayfinder:prototype
    on Nov 16, 2026
  2. jtklein-agents commented on Nov 16, 2026

    @jtklein-agents
    OwnerAuthor

    Resolution

    The pattern is acceptable for the whole Option family. Prototype (throwaway, never merged): prototype/option-typing at bc9c0e0. It holds src/app/store/Option.ts and typed copies of OutGroup and MultistateNumber in src/app/store/OptionSubclasses.prototype.ts. Typecheck, lint and the 37 store Jest suites pass on it.

    The pattern

    • Two type parameters on the base: class Option<Value = unknown, Owner = unknown>, with run: Owner. Each subclass names its value type and owner in the extends clause, for example extends Option<string[], OptionRun>.
    • The owner is a small module-local interface, holding only what that leaf reads from its owner. One interface per leaf file, not per class. The option base imports no store type. The interfaces stay after Run converts; Run satisfies them structurally and there is no later sweep.
    • Constructor: description and hoverInfo become optional parameters. No caller changes. The options argument gets an OptionSettings interface.
    • Annotation maps are unchanged. value: Value; stays a bare field.
    • error on the base is typed ValidationError | boolean | null, so MultistateNumber's boolean override compiles unchanged. errorMessage casts because of it.
    • Rule: a subclass never redeclares a base field to narrow its type. Class fields are defined here, so a redeclaration resets the field to undefined after super(). The type parameter does the narrowing.
    • The option base is its own early leaf.

    What the prototype measured

    • Typing the base alone clears 22 of the 26 baseline diagnostics: all 21 TS2554 constructor lines and the yup TS2304. Three remain in src/app/App.js and one in src/app/store/index.js.
    • Under --noImplicitAny, store/RunOptions.js drops from 89 extra diagnostics to 33 and store/AlignmentOptions.js to 11.
    • Still-JavaScript subclasses extend the base with no type arguments and are unaffected.

    Correction to the MobX research

    The "Jest deletes a typed field with no initializer" trap does not reproduce with this repo's Jest transform (jest/babelTransform.js: Babel 7.29.7, preset-typescript plus plugin-proposal-class-properties). The transform emits a define for the bare field, and Option.test.js passes with value: Value;, cache off.

    Exposed, not fixed

    MultistateNumber.error returns a boolean where the base returns a validation error or null. It goes on the list of bugs typing exposes.

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

Metadata

Metadata

Labels

wayfinder:prototype

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions