Skip to content

In JS, this in object literals is untyped #11072

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

Closed
waderyan opened this issue Sep 23, 2016 · 7 comments
Closed

In JS, this in object literals is untyped #11072

waderyan opened this issue Sep 23, 2016 · 7 comments
Assignees
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@waderyan
Copy link

From @ishuvalov on September 20, 2016 7:54

  • VSCode Version: Code 1.5.2 (66f37fd2a99eb9d628dd374d81d78835b410c39b, 2016-09-12T13:05:12.065Z)
  • OS Version: Darwin x64 15.6.0

Steps to Reproduce:

  1. Consider the following code:
(function(undefined) {
    MyView = Backbone.View.extend({
        secondFunc: function () {
            return;
        },

        mainFunc: function() {
            this.secondFunc()
        }
    });
})();
  1. The Goto Definition, Peek Definition and other IntelliSense features are not working for this.secondFunc() call.

Copied from original issue: microsoft/vscode#12306

@waderyan
Copy link
Author

From @joaomoreno on September 20, 2016 8:17

@ishuvalov This is going to be very hard to get from the language service, because this isn't really bound to anything by semantically analysing the code. It's only due to the implicit knowledge of how Backbone.View.extend works.

You could try using TypeScript, you'd get those language features all the way.

@waderyan waderyan self-assigned this Sep 23, 2016
@waderyan waderyan added the js label Sep 23, 2016
@waderyan
Copy link
Author

From @ishuvalov on September 20, 2016 8:38

@joaomoreno Thank you for your comment! Let's omit Backbone

(function(undefined) {
    var myObj = {
        secondFunc: function () {
            return;
        },

        mainFunc: function() {
            this.secondFunc()
        }
    };
})();

Still not working. I understand the difficulties of this context, but the feature could work just finding all symbolic definitions in the workspace (or even just a current file) and allowing user to choose from. This how Sublime Text 3 works.
Unfortunately the TypeScript is not an option for my project.

@waderyan
Copy link
Author

@ishuvalov thank you for opening this issue. I have repo'd this with JavaScript language service 2.0.2.

Sending this to the TypeScript team as they provide the JavaScript language service.

@waderyan waderyan added VS Code Tracked There is a VS Code equivalent to this issue and removed js labels Sep 23, 2016
@waderyan waderyan removed their assignment Sep 23, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

One option, in a .js file we can make the type of this to be the type of the containing object literal if no other better option is available.

@mhegazy mhegazy added the Salsa label Sep 23, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Sep 23, 2016
@sandersn
Copy link
Member

Basically, #8382, but only for JavaScript files, right? I think that could work.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

i guess so.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Sep 29, 2016
@mhegazy mhegazy modified the milestones: Future, TypeScript 2.1 Sep 29, 2016
@sandersn sandersn changed the title IntelliSense does not work for object property functions In JS, this in object literals is untyped Jun 11, 2018
@sandersn
Copy link
Member

The second repro is fixed (and has been for some time) and the first can be fixed by improving backbone's types.

@sandersn sandersn added the Fixed A PR has been merged for this issue label Jun 11, 2018
@mhegazy mhegazy modified the milestones: Future, TypeScript 3.0 Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed A PR has been merged for 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

3 participants