Skip to content

Strange typescript issue #3217

Answered by kubk
bellostom asked this question in General
Discussion options

You must be logged in to vote

Hi @bellostom
In TypeScript keyof Type skips private/protected fields:

class Test {
  public a = 1;
  private b = 1;
}

type Props = keyof Test; // Only 'a', not 'a' | 'b'

As a workaround you can change protected to public. As a solution I'd suggest to replace observe with reaction or autorun 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 on observe the same way it was done for makeObservable/makeAutoObservable:

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by bellostom
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants