Does useDefineForClassFields
*have* to be true?
#3216
Replies: 3 comments 1 reply
-
Consider this example: class Store {
propertyA: null | string = null;
propertyB?: string;
constructor() {
makeAutoObservable(this);
}
} Unless you set While it might work for you, TS is going to make |
Beta Was this translation helpful? Give feedback.
-
I will just add that we do support good old syntax without class fields: constructor() {
this.a = "";
makeAutoObservable(this);
} So as long as it actually translates to assigment, it will work. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer! |
Beta Was this translation helpful? Give feedback.
-
On the Lit project we have users using both Lit and MobX (often via lit-mobx). If they follow the configuration guide for TypeScript or instructions for upgrading to MobX 6 they will be told to set
useDefineForClassFields
totrue
, which will break Lit decorators.But does
useDefineForClassFields
really need to be set totrue
? What breaks in MobX is fields are initialized with set semantics? Most of the time (without a setter on the prototype) the result will be the same: an instance property.Beta Was this translation helpful? Give feedback.
All reactions