Skip to content

The value returned from computed(() => ...) shouldn't have a set(...) method #3767

Description

@Nokel81

Intended outcome:

Have strict and complete type safety to help with refactoring.

Actual outcome:

The return type of computed() and observable.box() both have set() and get() methods, but the return type of computed() doesn't have a set() method so a type error is thrown at run time.

How to reproduce the issue:

const myObservableValue = observable.box(10);
const myComputedValue = computed(() => myObservableValue.get() + 1);

/**
 * Uncaught:
 * Error: [MobX] [ComputedValue 'ComputedValue@2'] It is not possible to assign a new value to a computed value.
 *    at die (/node_modules/mobx/dist/mobx.cjs.development.js:89:11)
 *    at ComputedValue.set (/node_modules/mobx/dist/mobx.cjs.development.js:1448:7)
 */
myComputedValue.set(12);

Versions

mobx -> 6.10.9

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions