diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0f057e61667..e2b7efeac67 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -79,6 +79,7 @@ namespace ts { getIndexTypeOfType, getBaseTypes, getReturnTypeOfSignature, + getNonNullableType, getSymbolsInScope, getSymbolAtLocation, getShorthandAssignmentValueSymbol, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3a5602717c1..d924ac168c8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1770,6 +1770,7 @@ namespace ts { getIndexTypeOfType(type: Type, kind: IndexKind): Type; getBaseTypes(type: InterfaceType): ObjectType[]; getReturnTypeOfSignature(signature: Signature): Type; + getNonNullableType(type: Type): Type; getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolAtLocation(node: Node): Symbol; diff --git a/src/services/services.ts b/src/services/services.ts index 39dd688254d..d8abb4e6842 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -50,6 +50,7 @@ namespace ts { getStringIndexType(): Type; getNumberIndexType(): Type; getBaseTypes(): ObjectType[]; + getNonNullableType(): Type; } export interface Signature { @@ -735,6 +736,9 @@ namespace ts { ? this.checker.getBaseTypes(this) : undefined; } + getNonNullableType(): Type { + return this.checker.getNonNullableType(this); + } } class SignatureObject implements Signature { @@ -4366,7 +4370,7 @@ namespace ts { (location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration // get the signature from the declaration and write it const functionDeclaration = location.parent; - const allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getConstructSignatures() : type.getCallSignatures(); + const allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getNonNullableType().getConstructSignatures() : type.getNonNullableType().getCallSignatures(); if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } @@ -4541,10 +4545,8 @@ namespace ts { } // For properties, variables and local vars: show the type - // Also handle methods that have a union type (i.e. that may be undefined) if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & SymbolFlags.Variable || - symbolFlags & SymbolFlags.Method && type.flags & TypeFlags.Union || symbolKind === ScriptElementKind.localVariableElement || isThisExpression) { displayParts.push(punctuationPart(SyntaxKind.ColonToken)); @@ -4566,7 +4568,7 @@ namespace ts { symbolFlags & SymbolFlags.Signature || symbolFlags & SymbolFlags.Accessor || symbolKind === ScriptElementKind.memberFunctionElement) { - const allSignatures = type.getCallSignatures(); + const allSignatures = type.getNonNullableType().getCallSignatures(); addSignatureDisplayParts(allSignatures[0], allSignatures); } }