mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 13:45:34 -05:00
Get the type of a constructor as the type of the class
Fixes a bug when constructor overloads are improper and no signatures can be found.
This commit is contained in:
@@ -4628,7 +4628,8 @@ namespace ts {
|
||||
const symbolFlags = symbol.flags;
|
||||
let symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, location);
|
||||
let hasAddedSymbolInfo: boolean;
|
||||
const isThisExpression: boolean = location.kind === SyntaxKind.ThisKeyword && isExpression(location);
|
||||
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isExpression(location);
|
||||
const isConstructor = location.kind === SyntaxKind.ConstructorKeyword;
|
||||
let type: Type;
|
||||
|
||||
// Class at constructor site need to be shown as constructor apart from property,method, vars
|
||||
@@ -4639,7 +4640,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
let signature: Signature;
|
||||
type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
||||
type = isThisExpression
|
||||
? typeChecker.getTypeAtLocation(location)
|
||||
: isConstructor
|
||||
// For constructor, get type of the class.
|
||||
? typeChecker.getTypeOfSymbolAtLocation(symbol.parent, location)
|
||||
: typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
||||
if (type) {
|
||||
if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
const right = (<PropertyAccessExpression>location.parent).name;
|
||||
@@ -4737,9 +4743,7 @@ namespace ts {
|
||||
if (functionDeclaration.kind === SyntaxKind.Constructor) {
|
||||
// show (constructor) Type(...) signature
|
||||
symbolKind = ScriptElementKind.constructorImplementationElement;
|
||||
// For a constructor, `type` will be unknown.
|
||||
const showSymbol = symbol.declarations[0].kind === SyntaxKind.Constructor ? symbol.parent : type.symbol;
|
||||
addPrefixForAnyFunctionOrVar(showSymbol, symbolKind);
|
||||
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
|
||||
}
|
||||
else {
|
||||
// (function/method) symbol(..signature)
|
||||
|
||||
@@ -39,5 +39,6 @@
|
||||
////class d extends a.C { constructor() { [|super|](); }
|
||||
|
||||
const ranges = test.ranges();
|
||||
verify.referencesOf(ranges[0], ranges);
|
||||
verify.referencesOf(ranges[1], ranges);
|
||||
for (const ctr of ranges.slice(0, 3)) {
|
||||
verify.referencesOf(ctr, ranges);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class C {
|
||||
//// [|constructor|](n: number);
|
||||
//// [|constructor|](){}
|
||||
////}
|
||||
|
||||
verify.rangesReferenceEachOther();
|
||||
Reference in New Issue
Block a user