-
Hi I get the attached error from typescript when using observe. However, it works correctly in the browser, there is no error. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @bellostom class Test {
public a = 1;
private b = 1;
}
type Props = keyof Test; // Only 'a', not 'a' | 'b' As a workaround you can change Note for Mobx maintainers: The issue can be solved by introducing But since |
Beta Was this translation helpful? Give feedback.
-
Thanks @kubk for the comprehensive answer. |
Beta Was this translation helpful? Give feedback.
Hi @bellostom
In TypeScript
keyof Type
skips private/protected fields:As a workaround you can change
protected
topublic
. As a solution I'd suggest to replaceobserve
withreaction
orautorun
as recommended in docs: https://mobx.js.org/intercept-and-observe.html#intercept--observe-Note for Mobx maintainers: The issue can be solved by introducing
AdditionalKeys
onobserve
the same way it was done formakeObservable
/makeAutoObservable
:mobx/packages/mobx/src/api/makeObservable.ts
Line 26 in 1174004