Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint plugin] Conflict between TypeScript and ESLint when private property #3992

Open
baruchiro opened this issue Jan 5, 2025 · 0 comments
Labels

Comments

@baruchiro
Copy link

Intended outcome:

I'm trying to exclude a field from being made observable using makeObservable with false annotation, as documented in the MobX documentation. The following code should work:

import { makeObservable } from "mobx";

export class MyStore {
  private count = 0;

  constructor() {
    makeObservable(this, {
      count: false,
    });
  }
}

Actual outcome:

I'm getting contradictory TypeScript/ESLint errors:

  1. When the count property is not specified in makeObservable:
Missing annotation for `count`. To exclude a field, use `false` as annotation. (ESLint)
  1. When adding count: false as suggested by the first error:
Object literal may only specify known properties, and 'count' does not exist in type 'AnnotationsMap<this, never>'. (ts)

This creates a catch-22 situation where ESLint requires the annotation but then TypeScript doesn't accept it.

How to reproduce the issue:

I've created a minimal reproduction repository that demonstrates this issue:
example-mobx-eslint-bug

Steps to reproduce:

  1. Clone the repository
  2. Install dependencies
  3. Observe the TypeScript errors in the code

Versions

"mobx": "^6.13.5",
"mobx-react-lite": "^4.1.0",
"eslint-plugin-mobx": "^0.0.13"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant