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

Intellisense does not work for properties that are added after declaration #13271

Closed
mjbvz opened this issue Jan 3, 2017 · 5 comments
Closed
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jan 3, 2017

From @saravanaj on December 30, 2016 3:8

  • VSCode Version: 1.8.1
  • OS Version: Windows 8.1 Home

I am running code with --disable-extensions flag.

Steps to Reproduce:

  1. Write some code where properties are added to objects added after declaration. Intellisense does not work:
    actual

  2. If the properties are defined during declaration it works:
    expected

Copied from original issue: microsoft/vscode#17923

@mjbvz
Copy link
Contributor Author

mjbvz commented Jan 3, 2017

From @Spown on December 31, 2016 4:13

I think it is a proper behavior. If you had something like this:

var obj = {};
if (someGlobalVariable===true) {
  obj.test = {
    one: 1
  }
} else if (someGlobalVariable===false) {
  obj.test = "I'm a string now!"
}

obj

then Intellisense wouldn't really know whether the obj variable always has this test property and what type it is. Intellisense doesn't evaluate your code - it only makes assumptions where it can. Thats why you still have word suggestions:

as a compromise.

@mjbvz
Copy link
Contributor Author

mjbvz commented Jan 3, 2017

From @saravanaj on December 31, 2016 6:26

@Spown I agree it is impossible to autocomplete properties that are added conditionally, but the example I posted does not add any properties conditionally. The same code gives intellisense in Visual Studio.

The major use case where this type of intellisense is needed is when I namespace methods and properties like below:

In VS Code:
2016-12-31_115010

In Visual Studio: (which handles this perfectly)
vs

@mjbvz
Copy link
Contributor Author

mjbvz commented Jan 3, 2017

I verified this intellisense limitation for JS using both TS 2.1.5 and typescript@next.

I believe it may be a duplicate of an existing issue but wasn't able to find a proper parent, so feel free to mark it as such if that is the case. We already handle property assignment to the prototype for classes, so this may be similar.

@unional
Copy link
Contributor

unional commented Jan 6, 2017

Please note that obj = {}; // without var doesn't work either. This prevent JavaScript namespacing across multiple files.

microsoft/vscode#18196 (comment)

@mhegazy
Copy link
Contributor

mhegazy commented Jan 6, 2017

This is a duplicate of #7632

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 6, 2017
@mhegazy mhegazy closed this as completed Jan 6, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

4 participants