Skip to content

mobx-undecorate adds import incorrectly when importing mobx types #2415

Closed
@charliematters

Description

Intended outcome:

makeObservable gets added to the non-type import

Actual outcome:
makeObservable gets added to the first import even i that is only a type import

How to reproduce the issue:

Transforming this file:

import type { IReactionDisposer } from "mobx";
import { reaction, observable } from "mobx";

export default class Store {
  @observable counter = 0;

  removeReaction: IReactionDisposer;
  
  constructor() {
    this.removeReaction = reaction(() => this.counter, () => {
      console.log("it changed");
    });
  }

  cleanup() {
    this.removeReaction();
  }
}

Becomes this:

import type { IReactionDisposer, makeObservable } from "mobx";
import { reaction, observable } from "mobx";

export default class Store {
  counter = 0;

  removeReaction: IReactionDisposer;
  
  constructor() {
    makeObservable(this, {
      counter: observable
    });

    this.removeReaction = reaction(() => this.counter, () => {
      console.log("it changed");
    });
  }

  cleanup() {
    this.removeReaction();
  }
}

Versions
mobx: 5.15.4
typescript: 3.9.7

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