Repository navigation
feat: disallow set on computed values without a setter - #4728
Conversation
🦋 Changeset detectedLatest commit: fa412ec The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🟡 Changes recommended
The breaking public type change is incorrectly classified as a minor release.
1 open finding
What changed in this PR
This PR improves type safety by distinguishing read-only and writable computed values.
Changes:
- Adds
IWritableComputedValue<T>. - Narrows
computed()return types based on setter presence. - Adds TypeScript coverage and release notes.
| File | Description |
|---|---|
packages/mobx/src/mobx.ts |
Exports the writable interface. |
packages/mobx/src/core/computedvalue.ts |
Splits read-only and writable interfaces. |
packages/mobx/src/api/computed.ts |
Adds setter-aware overloads. |
packages/mobx/__tests__/base/typescript-tests.ts |
Tests inferred setter availability. |
.changeset/readonly-computed-type.md |
Documents and versions the change. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "mobx": minor | |||
|
The major / minor concern is valid. Yet I double-checked that this MobX version doesn't break MST / mobx-keystone, both of the libraries use |

Fixes #3767
This will break code like
const c: IComputedValue<number> = computed(() => x.get())so strictly speaking it should have been major. Yet the code that breaks is code was already wrong. Calling .set() on a computed without setter always throws, so the new error points at a bug