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

Recognize properties introduced by jQuery extend #31314

Open
amcasey opened this issue May 8, 2019 · 1 comment
Open

Recognize properties introduced by jQuery extend #31314

amcasey opened this issue May 8, 2019 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@amcasey
Copy link
Member

amcasey commented May 8, 2019

The old VS JS language service used to make runtime types available at design-time, allowing it to support jQuery's extend function for adding properties dynamically. The new one uses static types and so does not offer these symbols during completion, navigate-to, etc. We've had some customer inquiries about the possibility of supporting this functionality in the TS language service.

https://developercommunity.visualstudio.com/content/problem/529989/aspnet-在html-文件-js-智能提示失效.html
https://developercommunity.visualstudio.com/content/problem/560277/javascript-go-to-members-doesnt-work-with-property.html

The latter provided this example:

(function ($) {

    mynamespace.myClass = Class.extend({
      init: function (options) {
        // unless you specifically type this.testProperty = "abc" in JS, the 'Go to Members' will not find the below property even though it's explicitely defined.
      },
       __properties: {

       'testProperty': {
                /// <summary>
                /// Gets or sets the test property
                /// </summary>
                /// <value type="String"></value>

                get: function () {
                    return this._testProperty;
                },

                set: function (value) {
                    this._testProperty = value;
                }
            }
       }
   });

})(jQuery);
@sandersn
Copy link
Member

sandersn commented May 8, 2019

Notably, the example is based on John Resig's post from 2008, not on jquery.extend: https://johnresig.com/blog/simple-javascript-inheritance/

Jquery.extend is basically Object.assign, but is sometimes used for inheritance. Here's an example from a decade-old Stack Overflow question.

var A=function(){
};

$.extend(A.prototype, {
    init:function(){
        alert('A init');
    }
});
var B=function(){

};

$.extend(B.prototype,A.prototype,{
    init:function(){
        alert('B init');
    }
});
var p=new A();
p.init();
var x=new B();
x.init();

This is almost the same as the A.prototype = { init: ... } pattern and would be relatively easy to support. It just doesn't work right now because it $.extend works by side-effect.

@sandersn sandersn added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label May 8, 2019
@RyanCavanaugh RyanCavanaugh added the Suggestion An idea for TypeScript label Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants