Skip to content

Cannot decorate undefined property with deep inheritance #2633

@uqee

Description

@uqee

Reproducible example:

Please, have a look at
CodeSandBox.

Copy of the code
import { action, computed, makeObservable, observable } from "mobx";

class A {
  public constructor() {
    makeObservable(this);
  }

  // @action aAction = () => "aAction";

  // @computed get aGetter() {
  //   return "aGetter";
  // }

  // aMethod() {
  //   return "aMethod";
  // }

  // @observable aObservable = "aObservable";

  // aProperty = "aProperty";
}

class B extends A {
  public constructor() {
    super();
    makeObservable(this);
  }

  // UNCOMMENT ME TO BREAK
  // @action bAction = () => "bAction";

  @computed get bGetter() {
    return "bGetter";
  }

  bMethod() {
    return "bMethod";
  }

  // UNCOMMENT ME TO BREAK
  // @observable bObservable = "bObservable";

  bProperty = "bProperty";
}

class C extends B {
  public constructor() {
    super();
    makeObservable(this);
  }

  // UNCOMMENT ME TO REPAIR
  // @action cAction = () => "cAction";

  @computed get cGetter() {
    return "cGetter";
  }

  // cMethod() {
  //   return "cMethod";
  // }

  // UNCOMMENT ME TO REPAIR
  // @observable cObservable = "cObservable";

  // cProperty = "cProperty";
}

const c: C = new C();
console.log("OK", c);

How to reproduce the issue:

  1. Uncomment either one from

    // UNCOMMENT ME TO BREAK

    sections to see an error:

    Cannot decorate undefined property: ...
  2. Then comment either one from

    // COMMENT ME TO REPAIR

    sections to remove the error.

Versions:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions