-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fixes for type parameter name resolution in JS #26830
Conversation
when resolving type parameters in a prototype property assignment declaration. For example, this already works: ```js /** @template T */ function f(x) { this.x = x } /** @returns {T} */ f.protototype.m = function () { return this.x } ``` This now works too: ```js /** @template T */ var f = function (x) { this.x = x } /** @returns {T} */ f.prototype.m = function () { return this.x } ``` Fixes #26826
In the same way that they're looked up on prototype-property methods. That is, this previously worked: ```js /** @template T */ function f() { } /** @param {T} p */ f.prototype.m = function () { } ``` And this now works too: ```js /** @template T */ function f() { } f.prototype = { /** @param {T} p */ m() { } } ``` Note that the baselines still have errors; I'll file a followup bug for them.
This isn't working when calling the method: /**
* Should work for function declarations
* @constructor
* @template {string} K
* @template V
*/
function Multimap() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
Multimap.prototype.get = function (key) {
return this._map[key + ''];
}
/** @type {Multimap<"a" | "b", number>} */
const map = new Multimap();
const n = map.get("a"); At the last line, there's an error that |
* @param {K} key the key ok | ||
* @returns {V} the value ok | ||
*/ | ||
get(key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only works for methods, not properties with function values. That is, get: function(key) ...
doesn't work
@andy-ms Oof, yeah, that's a bigger limitation of the types we create for JSDoc generics. They're not really generics, and aren't instantiated using the normal instantiation code. That's not related to this fix — you'll see that the type is always just (Note that the 3.0 behaviour is that instances of Filed #26883 to track this. |
1. check for expando initializers in resolveEntityName
... when resolving type parameters in a prototype property assignment
declaration. For example, this already works:
This now works too:
Fixes #26826
2. Lookup type parameters on prototype-assignment methods
…In the same way that they're looked up on prototype-property methods.
That is, this previously worked:
And this now works too:
Note that the baselines still have errors; I filed #26831 to follow up on those.
Fixes #24230