From 26713c8721aefe852245b191cf1db129eb881f77 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Jul 2016 07:18:16 -0700 Subject: [PATCH] Expand top level of declared type in type alias declaration --- src/compiler/checker.ts | 13 +++++++------ src/compiler/types.ts | 1 + src/services/services.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33c6e750f16..60673b4a588 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2110,6 +2110,7 @@ namespace ts { return writeType(type, globalFlags); function writeType(type: Type, flags: TypeFormatFlags) { + const nextFlags = flags & ~TypeFormatFlags.InTypeAlias; // Write undefined/null type as any if (type.flags & TypeFlags.Intrinsic) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving @@ -2124,24 +2125,24 @@ namespace ts { writer.writeKeyword("this"); } else if (type.flags & TypeFlags.Reference) { - writeTypeReference(type, flags); + writeTypeReference(type, nextFlags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); } - else if (type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { + else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { const typeArguments = type.aliasTypeArguments; - writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, flags); + writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags); } else if (type.flags & TypeFlags.UnionOrIntersection) { - writeUnionOrIntersectionType(type, flags); + writeUnionOrIntersectionType(type, nextFlags); } else if (type.flags & TypeFlags.Anonymous) { - writeAnonymousType(type, flags); + writeAnonymousType(type, nextFlags); } else if (type.flags & TypeFlags.StringLiteral) { writer.writeStringLiteral(`"${escapeString((type).text)}"`); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e9ffb8bff72..5174bc5732b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1913,6 +1913,7 @@ namespace ts { InElementType = 0x00000040, // Writing an array or union element type UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type) InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type + InTypeAlias = 0x00000200, // Writing type in type alias declaration } export const enum SymbolFormatFlags { diff --git a/src/services/services.ts b/src/services/services.ts index 6586930c343..5bcd5ee28c4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4606,7 +4606,7 @@ namespace ts { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); - addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias)); } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist();