mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
fix merging of function and derived class (#47170)
This commit is contained in:
@@ -9900,7 +9900,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getBaseTypeNodeOfClass(type: InterfaceType): ExpressionWithTypeArguments | undefined {
|
||||
return getEffectiveBaseTypeNode(type.symbol.valueDeclaration as ClassLikeDeclaration);
|
||||
const decl = getClassLikeDeclarationOfSymbol(type.symbol);
|
||||
return decl && getEffectiveBaseTypeNode(decl);
|
||||
}
|
||||
|
||||
function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: readonly TypeNode[] | undefined, location: Node): readonly Signature[] {
|
||||
@@ -9926,8 +9927,8 @@ namespace ts {
|
||||
*/
|
||||
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
|
||||
if (!type.resolvedBaseConstructorType) {
|
||||
const decl = type.symbol.valueDeclaration as ClassLikeDeclaration;
|
||||
const extended = getEffectiveBaseTypeNode(decl);
|
||||
const decl = getClassLikeDeclarationOfSymbol(type.symbol);
|
||||
const extended = decl && getEffectiveBaseTypeNode(decl);
|
||||
const baseTypeNode = getBaseTypeNodeOfClass(type);
|
||||
if (!baseTypeNode) {
|
||||
return type.resolvedBaseConstructorType = undefinedType;
|
||||
|
||||
18
tests/baselines/reference/classFunctionMerging2.js
Normal file
18
tests/baselines/reference/classFunctionMerging2.js
Normal file
@@ -0,0 +1,18 @@
|
||||
//// [classFunctionMerging2.ts]
|
||||
declare abstract class A {
|
||||
constructor(p: number);
|
||||
a: number;
|
||||
}
|
||||
|
||||
declare function B(p: string): B;
|
||||
declare class B extends A {
|
||||
constructor(p: string);
|
||||
b: number;
|
||||
}
|
||||
|
||||
let b = new B("Hey")
|
||||
console.log(b.a)
|
||||
|
||||
//// [classFunctionMerging2.js]
|
||||
var b = new B("Hey");
|
||||
console.log(b.a);
|
||||
39
tests/baselines/reference/classFunctionMerging2.symbols
Normal file
39
tests/baselines/reference/classFunctionMerging2.symbols
Normal file
@@ -0,0 +1,39 @@
|
||||
=== tests/cases/compiler/classFunctionMerging2.ts ===
|
||||
declare abstract class A {
|
||||
>A : Symbol(A, Decl(classFunctionMerging2.ts, 0, 0))
|
||||
|
||||
constructor(p: number);
|
||||
>p : Symbol(p, Decl(classFunctionMerging2.ts, 1, 16))
|
||||
|
||||
a: number;
|
||||
>a : Symbol(A.a, Decl(classFunctionMerging2.ts, 1, 27))
|
||||
}
|
||||
|
||||
declare function B(p: string): B;
|
||||
>B : Symbol(B, Decl(classFunctionMerging2.ts, 3, 1), Decl(classFunctionMerging2.ts, 5, 33))
|
||||
>p : Symbol(p, Decl(classFunctionMerging2.ts, 5, 19))
|
||||
>B : Symbol(B, Decl(classFunctionMerging2.ts, 3, 1), Decl(classFunctionMerging2.ts, 5, 33))
|
||||
|
||||
declare class B extends A {
|
||||
>B : Symbol(B, Decl(classFunctionMerging2.ts, 3, 1), Decl(classFunctionMerging2.ts, 5, 33))
|
||||
>A : Symbol(A, Decl(classFunctionMerging2.ts, 0, 0))
|
||||
|
||||
constructor(p: string);
|
||||
>p : Symbol(p, Decl(classFunctionMerging2.ts, 7, 16))
|
||||
|
||||
b: number;
|
||||
>b : Symbol(B.b, Decl(classFunctionMerging2.ts, 7, 27))
|
||||
}
|
||||
|
||||
let b = new B("Hey")
|
||||
>b : Symbol(b, Decl(classFunctionMerging2.ts, 11, 3))
|
||||
>B : Symbol(B, Decl(classFunctionMerging2.ts, 3, 1), Decl(classFunctionMerging2.ts, 5, 33))
|
||||
|
||||
console.log(b.a)
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>b.a : Symbol(A.a, Decl(classFunctionMerging2.ts, 1, 27))
|
||||
>b : Symbol(b, Decl(classFunctionMerging2.ts, 11, 3))
|
||||
>a : Symbol(A.a, Decl(classFunctionMerging2.ts, 1, 27))
|
||||
|
||||
41
tests/baselines/reference/classFunctionMerging2.types
Normal file
41
tests/baselines/reference/classFunctionMerging2.types
Normal file
@@ -0,0 +1,41 @@
|
||||
=== tests/cases/compiler/classFunctionMerging2.ts ===
|
||||
declare abstract class A {
|
||||
>A : A
|
||||
|
||||
constructor(p: number);
|
||||
>p : number
|
||||
|
||||
a: number;
|
||||
>a : number
|
||||
}
|
||||
|
||||
declare function B(p: string): B;
|
||||
>B : typeof B
|
||||
>p : string
|
||||
|
||||
declare class B extends A {
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
constructor(p: string);
|
||||
>p : string
|
||||
|
||||
b: number;
|
||||
>b : number
|
||||
}
|
||||
|
||||
let b = new B("Hey")
|
||||
>b : B
|
||||
>new B("Hey") : B
|
||||
>B : typeof B
|
||||
>"Hey" : "Hey"
|
||||
|
||||
console.log(b.a)
|
||||
>console.log(b.a) : void
|
||||
>console.log : (...data: any[]) => void
|
||||
>console : Console
|
||||
>log : (...data: any[]) => void
|
||||
>b.a : number
|
||||
>b : B
|
||||
>a : number
|
||||
|
||||
13
tests/cases/compiler/classFunctionMerging2.ts
Normal file
13
tests/cases/compiler/classFunctionMerging2.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
declare abstract class A {
|
||||
constructor(p: number);
|
||||
a: number;
|
||||
}
|
||||
|
||||
declare function B(p: string): B;
|
||||
declare class B extends A {
|
||||
constructor(p: string);
|
||||
b: number;
|
||||
}
|
||||
|
||||
let b = new B("Hey")
|
||||
console.log(b.a)
|
||||
Reference in New Issue
Block a user