mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(53257): Illegal .d.ts class property definition for "constructor" generated from JavaScript (#53266)
This commit is contained in:
parent
f64f40d205
commit
437fd059be
@ -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)
|
||||
|
||||
20
tests/baselines/reference/constructorPropertyJs.js
Normal file
20
tests/baselines/reference/constructorPropertyJs.js
Normal 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;
|
||||
}
|
||||
19
tests/baselines/reference/constructorPropertyJs.symbols
Normal file
19
tests/baselines/reference/constructorPropertyJs.symbols
Normal 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))
|
||||
}
|
||||
}
|
||||
|
||||
20
tests/baselines/reference/constructorPropertyJs.types
Normal file
20
tests/baselines/reference/constructorPropertyJs.types
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
13
tests/cases/compiler/constructorPropertyJs.ts
Normal file
13
tests/cases/compiler/constructorPropertyJs.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user