fix(53257): Illegal .d.ts class property definition for "constructor" generated from JavaScript (#53266)

This commit is contained in:
Oleksandr T 2023-03-27 21:32:10 +03:00 committed by GitHub
parent f64f40d205
commit 437fd059be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 1 deletions

View File

@ -9530,7 +9530,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// need to be merged namespace members
return [];
}
if (p.flags & SymbolFlags.Prototype ||
if (p.flags & SymbolFlags.Prototype || p.escapedName === "constructor" ||
(baseType && getPropertyOfType(baseType, p.escapedName)
&& isReadonlySymbol(getPropertyOfType(baseType, p.escapedName)!) === isReadonlySymbol(p)
&& (p.flags & SymbolFlags.Optional) === (getPropertyOfType(baseType, p.escapedName)!.flags & SymbolFlags.Optional)

View File

@ -0,0 +1,20 @@
//// [a.js]
class C {
/**
* @param {any} a
*/
foo(a) {
this.constructor = a;
}
}
//// [a.d.ts]
declare class C {
/**
* @param {any} a
*/
foo(a: any): void;
}

View File

@ -0,0 +1,19 @@
=== /a.js ===
class C {
>C : Symbol(C, Decl(a.js, 0, 0))
/**
* @param {any} a
*/
foo(a) {
>foo : Symbol(C.foo, Decl(a.js, 0, 9))
>a : Symbol(a, Decl(a.js, 4, 8))
this.constructor = a;
>this.constructor : Symbol(C.constructor, Decl(a.js, 4, 12))
>this : Symbol(C, Decl(a.js, 0, 0))
>constructor : Symbol(C.constructor, Decl(a.js, 4, 12))
>a : Symbol(a, Decl(a.js, 4, 8))
}
}

View File

@ -0,0 +1,20 @@
=== /a.js ===
class C {
>C : C
/**
* @param {any} a
*/
foo(a) {
>foo : (a: any) => void
>a : any
this.constructor = a;
>this.constructor = a : any
>this.constructor : any
>this : this
>constructor : any
>a : any
}
}

View File

@ -0,0 +1,13 @@
// @allowJs: true
// @checkJs: true
// @declaration: true
// @emitDeclarationOnly: true
// @filename: /a.js
class C {
/**
* @param {any} a
*/
foo(a) {
this.constructor = a;
}
}