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
What do MobX 7 annotation maps need from TypeScript? #227
How does MobX 7 type makeObservable annotation maps in TypeScript: subclass overrides, non-public members (the AdditionalKeys generic), computed getters, and flow? Which of those shapes does the page store use, and does useDefineForClassFields: false in tsconfig.json matter?
Premise correction.tsconfig.json on master already has useDefineForClassFields: true and no experimentalDecorators (changed in AntonelliLab#504). That is the setting MobX documents as required for TypeScript.
Typing of annotation maps (MobX 7.1.7, TypeScript 5.9.3)
makeObservable<T, AdditionalKeys = never>(target, annotations: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?). Map keys are keyof T minus toString (public members only), all optional.
Private/protected members need the explicit generic, makeObservable<Store, "secret">(this, {...}); otherwise TS2353: Object literal may only specify known properties, and 'secret' does not exist in type 'AnnotationsMap<this, never>'. A key named in AdditionalKeys must then be annotated.
The annotation kind is not type-checked against the member, and override is a plain Annotation. All subclassing rules (override only prototype action/computed/flow/actionBound; no re-annotation except override; each class annotates its own members; no redeclaring annotated fields) are enforced at runtime in development builds, not by the types.
computed getters need nothing: the type is the getter's return type. A flow generator method stays typed as a Generator; flowResult(...) casts it to CancellablePromise<R>. actionBound, observableRef, observableShallow leave the member's declared type unchanged.
MobX 7 versus 6: the namespaced forms (observable.ref, action.bound, flow.bound, computed.struct, comparer.*) are gone in favour of named exports and are now type errors; makeObservable's annotations argument is required; legacy decorators are removed; computed(fn) returns an IComputedValue without set() (7.1.0). AnnotationsMap and AdditionalKeys are unchanged.
What the page store uses (53 classes, 47 annotation maps, 317 entries)
No flow, flowResult, actionBound, observableShallow, makeAutoObservable, options argument, AdditionalKeys generic, private or #private member. So the non-public and flow typing cases do not arise in the current store.
One finding outside the types. Jest's Babel transform uses @babel/preset-typescript 7 without allowDeclareFields, which deletes type-only class fields (confirmed by transforming a sample). Option.value (Option.js:43) is declared without an initializer and annotated before it is assigned, so as a typed field with no initializer in a .ts file it would hit MobX's "Field not found" runtime error under Jest.
Not verified: what the Vite renderer build emits for that same type-only field; mobx-utils 6.1.1 typings against MobX 7; runtime error strings are quoted from source, not triggered.
Activity
jtklein-agents commentedon Nov 16, 2026
Resolution
Findings: https://github.com/jtklein-agents/raxmlGUI/blob/research/mobx7-typescript/docs/research/mobx7-typescript.md
Premise correction.
tsconfig.jsononmasteralready hasuseDefineForClassFields: trueand noexperimentalDecorators(changed in AntonelliLab#504). That is the setting MobX documents as required for TypeScript.Typing of annotation maps (MobX 7.1.7, TypeScript 5.9.3)
makeObservable<T, AdditionalKeys = never>(target, annotations: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?). Map keys arekeyof TminustoString(public members only), all optional.makeObservable<Store, "secret">(this, {...}); otherwiseTS2353: Object literal may only specify known properties, and 'secret' does not exist in type 'AnnotationsMap<this, never>'. A key named inAdditionalKeysmust then be annotated.overrideis a plainAnnotation. All subclassing rules (override only prototypeaction/computed/flow/actionBound; no re-annotation exceptoverride; each class annotates its own members; no redeclaring annotated fields) are enforced at runtime in development builds, not by the types.computedgetters need nothing: the type is the getter's return type. Aflowgenerator method stays typed as aGenerator;flowResult(...)casts it toCancellablePromise<R>.actionBound,observableRef,observableShallowleave the member's declared type unchanged.observable.ref,action.bound,flow.bound,computed.struct,comparer.*) are gone in favour of named exports and are now type errors;makeObservable'sannotationsargument is required; legacy decorators are removed;computed(fn)returns anIComputedValuewithoutset()(7.1.0).AnnotationsMapandAdditionalKeysare unchanged.What the page store uses (53 classes, 47 annotation maps, 317 entries)
computedon getters 164;action91 (66 arrow fields, 22asyncarrow fields, 3 prototype methods);observable58;observableRef1 (Run.js:64);override3 (AlignmentOptions.js:120,AlignmentOptions.js:137,RunOptions.js:441).flow,flowResult,actionBound,observableShallow,makeAutoObservable, options argument,AdditionalKeysgeneric,privateor#privatemember. So the non-public andflowtyping cases do not arise in the current store.One finding outside the types. Jest's Babel transform uses
@babel/preset-typescript7 withoutallowDeclareFields, which deletes type-only class fields (confirmed by transforming a sample).Option.value(Option.js:43) is declared without an initializer and annotated before it is assigned, so as a typed field with no initializer in a.tsfile it would hit MobX's "Field not found" runtime error under Jest.Not verified: what the Vite renderer build emits for that same type-only field;
mobx-utils6.1.1 typings against MobX 7; runtime error strings are quoted from source, not triggered.