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

Salsa - Recognize dynamically added object properties #10868

Closed
abgivant opened this issue Sep 12, 2016 · 22 comments
Closed

Salsa - Recognize dynamically added object properties #10868

abgivant opened this issue Sep 12, 2016 · 22 comments
Assignees
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@abgivant
Copy link

I have been trying to use Visual Studio Code as my primary editor, and one thing I've noticed as far as the JS intellisense goes, is that intellisense is provided for object properties that are statically defined when an object is declared, but it is not for properties dynamically added to the object after it has been declared. Are there currently any plans to support this feature?

Example:

image

Thanks!

@abgivant abgivant changed the title Salsa - Recognize dynamically added properties Salsa - Recognize dynamically added object properties Sep 12, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Sep 12, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2016

We have been thinking about this scenario lately. we are experimenting with "evolving" types with assignments.

@abgivant
Copy link
Author

Cool. Would that change also include a type change following through a reassignment?

Example:

image
image

In this case, arr2 was initialized without a type, then later assigned to be an array, but this change doesn't get picked up, as its type is still displayed as any.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2016

yes. the proposal so far applies to:

var x = {};
x.a = 0;

var y = [];
y.push(1);

var z = null;
z = {a: 0};

var w;
w = [1,2];

you can read more about this in #10566

@abgivant
Copy link
Author

abgivant commented Oct 5, 2016

Just checking in, but has any work or additional discussion happened regarding this issue recently?

@Arlen22
Copy link

Arlen22 commented Jun 14, 2017

This one is huge for me, and the only alternative I can think of is to download the Visual Studio Community edition, but that is a huge installation for my laptop.

It would be incredibly useful to have this functionality.

@barisusakli
Copy link

SublimeText3 does this really well but I think it uses some kind of search to find definitions.

@kukoss
Copy link

kukoss commented Jun 14, 2017

@barisusakli I have to be honest with you, WebStorm is so far the best editor I worked with. It's fully customizable and its intelli sense is great. For javascript and typescript. However it is a paid option (50 per yer), it saves lots of time :)

@pciazynski
Copy link

It's affect me too in VSCode, I hope that there some chances to fix this :)

@PRossetti
Copy link

I'm having the exact same issue. I have already lost several hours of my time trying to make it work. I can't understand how can Atom and Sublime Text do this but VS Code doesn't.
All I want is the go to definition / find all references to work in my angularjs / javascript proyect throw all .js files but it isn't working at all.
Are you working on it? Would it ever work?

@icetbr
Copy link

icetbr commented Aug 10, 2017

Same applies for the following I believe:

var a = {
  c: 2,
  b() {
    return this.c;
  }
}

@mhegazy mhegazy added the Salsa label Aug 31, 2017
@realjeffbrooks
Copy link

Any update on this one? I run into this a fair bit.

@TimvdEijnden
Copy link

Yes I'd also like an update about this please.

@pursehouse
Copy link

looks like this specific feature has been asked for in several places for years... still not done? It exists in Eclipse...

file1.js
foo = {};

file2.js
foo.bar = {};

file3.js
test = foo.bar;

those foo and bar references in file3.js are both navigable as references to the definitions in file1&2

@pgross41
Copy link

pgross41 commented Jan 8, 2018

I have what I assume is the same issue, I am using backbonejs so there are a lot of object expressions. It does not recognize any of the functions/variables. For example, this.render on line 4 is unable to "go to definition"

var document = Backbone.View.extend({
    
    initialize: function() {
        this.listenTo(this.model, "change", this.render);
    },
    
    render: function() {
        console.log('rendering');
    }
    
});

@spiritwindy

This comment has been minimized.

@spiritwindy
Copy link

it Support??

var w={};
function chang(w) {
    w.__proto__=Array.prototype;
}
chang(w);
w//want to be type Array

@RyanCavanaugh RyanCavanaugh assigned sandersn and unassigned ahejlsberg Aug 8, 2018
@sandersn
Copy link
Member

sandersn commented Aug 8, 2018

Salsa now supports the most common patterns of dynamically adding properties, as explained on the wiki, so I will close this issue. Please open new issues for specific patterns that are still not supported.

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 8, 2018
@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Aug 8, 2018
@sandersn sandersn closed this as completed Aug 8, 2018
@nicothed
Copy link

I'd like to switch to VS Code (from Webstorm) for my Node.js app, but this might be a deal breaker. I need to be able to type F12 (or "Go to Definition") for functions from imported modules.
Are there Extensions one can install to allow this seemingly very basic function?
Webstorm has been doing it forever, and interestingly, my functions come up in the intellisense, but still can't see the definition.

Update:
After a bit of fiddling, I see that adding this at the top seems to ease some of the pain:
var du = {} // short for dishlyUtils
module.exports = du

du.myFunc() { ... }

works, except from within the same module.

Ah, and if I put this line at the end of file, it seems to work everywhere!??
module.exports = du

I don't understand how Microsoft could mess up such an essential and honestly quite basic functionality (I remember using it a lot in 2000 in Visual Studio.Net already).

@sandersn
Copy link
Member

@nicothed Can you open a new issue for the bug you found? I'd like to track each issue separately, and yours looks different from the specifics of the original bug.

You can also try typescript@next. I improved typing of module.exports within its own file recently. You can npm install it and then point VS Code to its folder with "typescript.tsdk": "/path/to/typescript/next".

@sloantash
Copy link

I'd just like to chime in that I too wish this basic functionality worked better. My use case is like this:
function SomeConstructor() {
var self=this;
self.foobar = function(){
...
}

self.foobar();

}
^^^ Hovering here and clicking go to definition or find all references shows no results. As mentioned, Sublime and Atom both handle this flawlessly. Please work this out!

@white-room
Copy link

Seems like a pretty basic use case and I was surprised that the functionality is missing. Really a pain if you prefer factory functions instead of classes.

@marcusx2
Copy link

marcusx2 commented Jun 3, 2021

Will this be added, like, ever? It was first asked 5 years ago. This is basic functionality and without it makes VSCode unusable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests