You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prototype the typing pattern on Option and two subclasses #229
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?
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 yupTS2304. 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.
Activity
jtklein-agents commentedon Nov 16, 2026
Resolution
The pattern is acceptable for the whole Option family. Prototype (throwaway, never merged):
prototype/option-typingatbc9c0e0. It holdssrc/app/store/Option.tsand typed copies ofOutGroupandMultistateNumberinsrc/app/store/OptionSubclasses.prototype.ts. Typecheck, lint and the 37 store Jest suites pass on it.The pattern
class Option<Value = unknown, Owner = unknown>, withrun: Owner. Each subclass names its value type and owner in theextendsclause, for exampleextends Option<string[], OptionRun>.Runconverts;Runsatisfies them structurally and there is no later sweep.descriptionandhoverInfobecome optional parameters. No caller changes. The options argument gets anOptionSettingsinterface.value: Value;stays a bare field.erroron the base is typedValidationError | boolean | null, soMultistateNumber's boolean override compiles unchanged.errorMessagecasts because of it.undefinedaftersuper(). The type parameter does the narrowing.What the prototype measured
TS2554constructor lines and theyupTS2304. Three remain insrc/app/App.jsand one insrc/app/store/index.js.--noImplicitAny,store/RunOptions.jsdrops from 89 extra diagnostics to 33 andstore/AlignmentOptions.jsto 11.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-typescriptplusplugin-proposal-class-properties). The transform emits a define for the bare field, andOption.test.jspasses withvalue: Value;, cache off.Exposed, not fixed
MultistateNumber.errorreturns a boolean where the base returns a validation error ornull. It goes on the list of bugs typing exposes.