mobx-keystone
mobx-keystone copied to clipboard
No static checks to prevent assignment outside of an action
Hey! You've setup a great library, thank you for that. I was wondering if I'm doing something wrong or if I'm not understanding something. When I create a very basic store:
import { prop, model, Model, modelAction } from "mobx-keystone";
@model("AtsDash/Debug")
export class Debug extends Model({
count: prop<number>(),
}) {
@modelAction
increment() {
this.count += 1;
}
@modelAction
decrement() {
this.count -= 1;
}
}
And then try to use it like this:
import { describe, expect, it } from "vitest";
import { Debug } from "./model";
describe("model", () => {
it("should work", () => {
expect.assertions(1);
const store = new Debug({ count: 0 });
store.count = 1; // this will compile, no problem
expect(store.count).toBe(1);
});
});
It will not complain about me setting a property outside of an action when compiling. It will only complain about this at runtime. Maybe this is working as intended but since good typescript support is a feature of this library I thought I would ask.
Thank you
Basically because for typescript there's no difference between the count in this and the count in store ☹️
Too bad, but thank you for the quick response.