Skip to content

Commit 437fd05

Browse files
authored
fix(53257): Illegal .d.ts class property definition for "constructor" generated from JavaScript (microsoft#53266)
1 parent f64f40d commit 437fd05

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9530,7 +9530,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
95309530
// need to be merged namespace members
95319531
return [];
95329532
}
9533-
if (p.flags & SymbolFlags.Prototype ||
9533+
if (p.flags & SymbolFlags.Prototype || p.escapedName === "constructor" ||
95349534
(baseType && getPropertyOfType(baseType, p.escapedName)
95359535
&& isReadonlySymbol(getPropertyOfType(baseType, p.escapedName)!) === isReadonlySymbol(p)
95369536
&& (p.flags & SymbolFlags.Optional) === (getPropertyOfType(baseType, p.escapedName)!.flags & SymbolFlags.Optional)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [a.js]
2+
class C {
3+
/**
4+
* @param {any} a
5+
*/
6+
foo(a) {
7+
this.constructor = a;
8+
}
9+
}
10+
11+
12+
13+
14+
//// [a.d.ts]
15+
declare class C {
16+
/**
17+
* @param {any} a
18+
*/
19+
foo(a: any): void;
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== /a.js ===
2+
class C {
3+
>C : Symbol(C, Decl(a.js, 0, 0))
4+
5+
/**
6+
* @param {any} a
7+
*/
8+
foo(a) {
9+
>foo : Symbol(C.foo, Decl(a.js, 0, 9))
10+
>a : Symbol(a, Decl(a.js, 4, 8))
11+
12+
this.constructor = a;
13+
>this.constructor : Symbol(C.constructor, Decl(a.js, 4, 12))
14+
>this : Symbol(C, Decl(a.js, 0, 0))
15+
>constructor : Symbol(C.constructor, Decl(a.js, 4, 12))
16+
>a : Symbol(a, Decl(a.js, 4, 8))
17+
}
18+
}
19+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== /a.js ===
2+
class C {
3+
>C : C
4+
5+
/**
6+
* @param {any} a
7+
*/
8+
foo(a) {
9+
>foo : (a: any) => void
10+
>a : any
11+
12+
this.constructor = a;
13+
>this.constructor = a : any
14+
>this.constructor : any
15+
>this : this
16+
>constructor : any
17+
>a : any
18+
}
19+
}
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @declaration: true
4+
// @emitDeclarationOnly: true
5+
// @filename: /a.js
6+
class C {
7+
/**
8+
* @param {any} a
9+
*/
10+
foo(a) {
11+
this.constructor = a;
12+
}
13+
}

0 commit comments

Comments
 (0)