Skip to content

Commit 9f9eed4

Browse files
authored
Read the base construct signature from the static base type, not the instance base (#41767)
1 parent 9a957e7 commit 9f9eed4

6 files changed

+130
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6772,7 +6772,7 @@ namespace ts {
67726772
!some(getSignaturesOfType(staticType, SignatureKind.Construct));
67736773
const constructors = isNonConstructableClassLikeInJsFile ?
67746774
[factory.createConstructorDeclaration(/*decorators*/ undefined, factory.createModifiersFromModifierFlags(ModifierFlags.Private), [], /*body*/ undefined)] :
6775-
serializeSignatures(SignatureKind.Construct, staticType, baseTypes[0], SyntaxKind.Constructor) as ConstructorDeclaration[];
6775+
serializeSignatures(SignatureKind.Construct, staticType, staticBaseType, SyntaxKind.Constructor) as ConstructorDeclaration[];
67766776
const indexSignatures = serializeIndexSignatures(classType, baseTypes[0]);
67776777
addResult(setTextRange(factory.createClassDeclaration(
67786778
/*decorators*/ undefined,

tests/baselines/reference/jsDeclarationsClasses.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,6 @@ export class N<T> extends L {
579579
* @extends {N<U>}
580580
*/
581581
export class O<U> extends N<U> {
582-
/**
583-
* @param {U} param
584-
*/
585-
constructor(param: U);
586582
another2: U;
587583
}
588584
declare const VariableBase_base: any;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//// [index.js]
2+
export class Super {
3+
/**
4+
* @param {string} firstArg
5+
* @param {string} secondArg
6+
*/
7+
constructor(firstArg, secondArg) { }
8+
}
9+
10+
export class Sub extends Super {
11+
constructor() {
12+
super('first', 'second');
13+
}
14+
}
15+
16+
//// [index.js]
17+
"use strict";
18+
var __extends = (this && this.__extends) || (function () {
19+
var extendStatics = function (d, b) {
20+
extendStatics = Object.setPrototypeOf ||
21+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23+
return extendStatics(d, b);
24+
};
25+
return function (d, b) {
26+
extendStatics(d, b);
27+
function __() { this.constructor = d; }
28+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29+
};
30+
})();
31+
exports.__esModule = true;
32+
exports.Sub = exports.Super = void 0;
33+
var Super = /** @class */ (function () {
34+
/**
35+
* @param {string} firstArg
36+
* @param {string} secondArg
37+
*/
38+
function Super(firstArg, secondArg) {
39+
}
40+
return Super;
41+
}());
42+
exports.Super = Super;
43+
var Sub = /** @class */ (function (_super) {
44+
__extends(Sub, _super);
45+
function Sub() {
46+
return _super.call(this, 'first', 'second') || this;
47+
}
48+
return Sub;
49+
}(Super));
50+
exports.Sub = Sub;
51+
52+
53+
//// [index.d.ts]
54+
export class Super {
55+
/**
56+
* @param {string} firstArg
57+
* @param {string} secondArg
58+
*/
59+
constructor(firstArg: string, secondArg: string);
60+
}
61+
export class Sub extends Super {
62+
constructor();
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
export class Super {
3+
>Super : Symbol(Super, Decl(index.js, 0, 0))
4+
5+
/**
6+
* @param {string} firstArg
7+
* @param {string} secondArg
8+
*/
9+
constructor(firstArg, secondArg) { }
10+
>firstArg : Symbol(firstArg, Decl(index.js, 5, 16))
11+
>secondArg : Symbol(secondArg, Decl(index.js, 5, 25))
12+
}
13+
14+
export class Sub extends Super {
15+
>Sub : Symbol(Sub, Decl(index.js, 6, 1))
16+
>Super : Symbol(Super, Decl(index.js, 0, 0))
17+
18+
constructor() {
19+
super('first', 'second');
20+
>super : Symbol(Super, Decl(index.js, 0, 0))
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
export class Super {
3+
>Super : Super
4+
5+
/**
6+
* @param {string} firstArg
7+
* @param {string} secondArg
8+
*/
9+
constructor(firstArg, secondArg) { }
10+
>firstArg : string
11+
>secondArg : string
12+
}
13+
14+
export class Sub extends Super {
15+
>Sub : Sub
16+
>Super : Super
17+
18+
constructor() {
19+
super('first', 'second');
20+
>super('first', 'second') : void
21+
>super : typeof Super
22+
>'first' : "first"
23+
>'second' : "second"
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @outDir: /out
4+
// @lib: es6
5+
// @declaration: true
6+
// @filename: index.js
7+
export class Super {
8+
/**
9+
* @param {string} firstArg
10+
* @param {string} secondArg
11+
*/
12+
constructor(firstArg, secondArg) { }
13+
}
14+
15+
export class Sub extends Super {
16+
constructor() {
17+
super('first', 'second');
18+
}
19+
}

0 commit comments

Comments
 (0)