You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default TypeScript will not allow you to annotate private fields. This can be overcome by explicitly passing the relevant private fields as generic argument, like this: makeObservable<MyStore, "privateField" | "privateField2">(this, { privateField: observable, privateField2: observable })
I'm struggling to see how you gain any type safety by specifying the AdditionalKeys ( "privateField" | "privateField2" in this case). You could actually make up anything you want for those keys, and TypeScript would be none the wiser. While I normally avoid using any like the plague, I'd argue you that in this case, it's actually the correct thing to do. It's a signal to anyone reading the code
that the overrides that aren't part of the public API not able to be type safe.
I think the documentation should make this more clear.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Limitation 8 says:
I'm struggling to see how you gain any type safety by specifying the
AdditionalKeys
("privateField" | "privateField2"
in this case). You could actually make up anything you want for those keys, and TypeScript would be none the wiser. While I normally avoid usingany
like the plague, I'd argue you that in this case, it's actually the correct thing to do. It's a signal to anyone reading the codethat the overrides that aren't part of the public API not able to be type safe.
I think the documentation should make this more clear.
Beta Was this translation helpful? Give feedback.
All reactions