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

TypeScript 3.6.4 incorrectly infers type from observable method #2178

Closed
7 of 8 tasks
nvigne opened this issue Oct 25, 2019 · 3 comments
Closed
7 of 8 tasks

TypeScript 3.6.4 incorrectly infers type from observable method #2178

nvigne opened this issue Oct 25, 2019 · 3 comments

Comments

@nvigne
Copy link

nvigne commented Oct 25, 2019

I have a:

  1. Issue:
  • Provide a minimal sample reproduction. Create a reproduction based on this sandbox
  • Did you check this issue wasn't filed before?
  • Elaborate on your issue. What behavior did you expect?
  • State the versions of MobX and relevant libraries. Which browser / node / ... version?
  1. Idea:
  • Do you think others will benefit from this change as well and it should in core package (see also mobx-utils)?
  • Are you willing to (attempt) a PR yourself?

Hi,

I'm working with MobX and TypeScript and I notice that TypeScript incorrectly infers types from observable.

TypeScript version : 3.6.4 (LKG)

import { observable } from 'mobx'

const myObservable = observable({ id: 'myId' });
myObservable.id = 'newId'

The compilation error we get from TypeScript when trying to compile is the following:

error TS2339: Property 'id' does not exist on type 'ObservableSet<any>'.
myObservable.id = 'newId'

If we take a closer look at the issue, we can see that TypeScript infers that myObservable is typeof ObservableSet when it should be simply the type of the parameter pass to observable.

I can have a look to try to fix the issue on mobx side, the only condition is too being able to upgrade the TypeScript version up to 3.6.4

@nvigne
Copy link
Author

nvigne commented Oct 25, 2019

In fact, it seems to repro on older version of TypeScript as well, I will try to investigate a bit more.

@nvigne
Copy link
Author

nvigne commented Oct 25, 2019

The issue seems due to the fact that I was missing the lib es2016 in my tsconfig causing the TypeScript engine to consider the Set type as an object type. Closing for now. Maybe it may require to add some information when building a new project.

@lock
Copy link

lock bot commented Dec 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants