Skip to content

App works, but DevTools gives error "TypeError: this.todos is undefined" #75

Description

@darkdark87

The setup is simple. React with MobX and TypeScript along with MobX DevTools. The app is pretty much a copy paste of the 10 min todo introduction of MobX. The app works, but once I try to inspect the content of my store with DevTools I receive an error:

image

The code for the store is as follows:

export default class ObservableTodoStore {
    @observable 
    todos: any[] = [];
    @observable 
    pendingRequests: number = 0;

    constructor() {
        autorun(() => console.log(this.report));
    }

    @computed 
    get completedTodosCount() {
        return this.todos.filter(
            (todo: any) => todo.completed === true
        ).length;
    }

    @computed 
    get report() {
        if (this.todos.length === 0) {
            return '<none>';
        }
        return `Next todo: "${this.todos[0].task}". ` +
            `Progress: ${this.completedTodosCount}/${this.todos.length}`;
    }

    @action
    addTodo(task: any) {
        this.todos.push({
            task: task,
            completed: false,
            assignee: null
        });
    }
}

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions