a1089893bd
* Fixes #26128 - signature comp for jsdoc @class. Another issue caused by js functions tagged with jsdoc `@constructor` not having construct signatures. A jsdoc function type that constructs a type (`function(new: Ex)`), has a construct signature and return value inferred as the constructed type where as a jsdoc `@constructor` has no construct signatures, and it's call signature has a void return type (or undefined). i.e: ```javascript /** @constructor **/ function E() {}; // typeof E -> call signature: () => void /** @param {function(new: E)} d */ function c(d) {} // typeof d -> construct: () => E ``` -- This commit fixes this (in an inelegant way) by considering `@class` function signatures as construct signatures and synthesizing it's return value _only for signature comparison_. There might be a slight performance hit, since the synthesized return value is not cached; but changing the `@class` function's return type in `getReturnTypeOfSignature` causes other issues. * Update jsdoc function test to fix mistake.
72 lines
1.2 KiB
TypeScript
72 lines
1.2 KiB
TypeScript
// @allowJs: true
|
|
// @checkJs: true
|
|
// @noEmit: true
|
|
// @noImplicitAny: true
|
|
|
|
// @Filename: functions.js
|
|
|
|
/**
|
|
* @param {function(this: string, number): number} c is just passing on through
|
|
* @return {function(this: string, number): number}
|
|
*/
|
|
function id1(c) {
|
|
return c
|
|
}
|
|
|
|
var x = id1(function (n) { return this.length + n });
|
|
|
|
/**
|
|
* @param {function(new: { length: number }, number): number} c is just passing on through
|
|
* @return {function(new: { length: number }, number): number}
|
|
*/
|
|
function id2(c) {
|
|
return c
|
|
}
|
|
|
|
class C {
|
|
/** @param {number} n */
|
|
constructor(n) {
|
|
this.length = n;
|
|
}
|
|
}
|
|
|
|
var y = id2(C);
|
|
var z = new y(12);
|
|
z.length;
|
|
|
|
/** @type {function ("a" | "b", 1 | 2): 3 | 4} */
|
|
var f = function (ab, onetwo) { return ab === "a" ? 3 : 4; }
|
|
|
|
|
|
/**
|
|
* @constructor
|
|
* @param {number} n
|
|
*/
|
|
function D(n) {
|
|
this.length = n;
|
|
}
|
|
|
|
var y2 = id2(D);
|
|
var z2 = new y2(33);
|
|
z2.length;
|
|
|
|
|
|
/**
|
|
* @param {function(new: D, number)} dref
|
|
* @return {D}
|
|
*/
|
|
var construct = function(dref) { return new dref(33); }
|
|
var z3 = construct(D);
|
|
z3.length;
|
|
|
|
|
|
/**
|
|
* @constructor
|
|
* @param {number} n
|
|
*/
|
|
var E = function(n) {
|
|
this.not_length_on_purpose = n;
|
|
};
|
|
|
|
|
|
var y3 = id2(E);
|