From c5a2969255e7b1c1d45c3b6bb276455e6992ed8d Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 25 Nov 2015 11:41:51 -0800 Subject: [PATCH] check for null --- src/services/services.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 54c76a063b2..b53ff02e195 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4247,26 +4247,30 @@ namespace ts { } else { // Method/function type parameter - let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeParameter).parent; - if (declaration && isFunctionLikeKind(declaration.kind)) { - let signature = typeChecker.getSignatureFromDeclaration(declaration); - if (declaration.kind === SyntaxKind.ConstructSignature) { - displayParts.push(keywordPart(SyntaxKind.NewKeyword)); + let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeParameter); + declaration = declaration ? declaration.parent : undefined; + + if (declaration) { + if (isFunctionLikeKind(declaration.kind)) { + let signature = typeChecker.getSignatureFromDeclaration(declaration); + if (declaration.kind === SyntaxKind.ConstructSignature) { + displayParts.push(keywordPart(SyntaxKind.NewKeyword)); + displayParts.push(spacePart()); + } + else if (declaration.kind !== SyntaxKind.CallSignature && (declaration).name) { + addFullSymbolName(declaration.symbol); + } + addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); + } + else { + // Type alias type parameter + // For example + // type list = T[]; // Both T will go through same code path + displayParts.push(keywordPart(SyntaxKind.TypeKeyword)); displayParts.push(spacePart()); - } - else if (declaration.kind !== SyntaxKind.CallSignature && (declaration).name) { addFullSymbolName(declaration.symbol); + writeTypeParametersOfSymbol(declaration.symbol, sourceFile); } - addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); - } - else { - // Type alias type parameter - // For example - // type list = T[]; // Both T will go through same code path - displayParts.push(keywordPart(SyntaxKind.TypeKeyword)); - displayParts.push(spacePart()); - addFullSymbolName(declaration.symbol); - writeTypeParametersOfSymbol(declaration.symbol, sourceFile); } } }