Correct symbol display for type parameter of mapped type

This commit is contained in:
Anders Hejlsberg
2016-11-07 09:43:20 -08:00
parent 5de63a74eb
commit de93876abe

View File

@@ -272,11 +272,9 @@ namespace ts.SymbolDisplay {
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
addFullSymbolName(symbol);
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.InKeyword));
displayParts.push(spacePart());
if (symbol.parent) {
// Class/Interface type parameter
addInPrefix();
addFullSymbolName(symbol.parent, enclosingDeclaration);
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
}
@@ -288,6 +286,7 @@ namespace ts.SymbolDisplay {
if (declaration) {
if (isFunctionLikeKind(declaration.kind)) {
addInPrefix();
const signature = typeChecker.getSignatureFromDeclaration(<SignatureDeclaration>declaration);
if (declaration.kind === SyntaxKind.ConstructSignature) {
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
@@ -298,10 +297,11 @@ namespace ts.SymbolDisplay {
}
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
}
else {
else if (declaration.kind === SyntaxKind.TypeAliasDeclaration) {
// Type alias type parameter
// For example
// type list<T> = T[]; // Both T will go through same code path
addInPrefix();
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
displayParts.push(spacePart());
addFullSymbolName(declaration.symbol);
@@ -439,6 +439,12 @@ namespace ts.SymbolDisplay {
}
}
function addInPrefix() {
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.InKeyword));
displayParts.push(spacePart());
}
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);