Skip to content

Commit 332b316

Browse files
author
Yui T
committed
Emit declaration file which inferred type alias with its value
1 parent fcac9c4 commit 332b316

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,8 +2150,13 @@ namespace ts {
21502150
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
21512151
}
21522152
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) {
2153-
const typeArguments = type.aliasTypeArguments;
2154-
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
2153+
if (type.flags & TypeFlags.Anonymous || !(flags & TypeFormatFlags.UseTypeAliasValue)) {
2154+
const typeArguments = type.aliasTypeArguments;
2155+
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
2156+
}
2157+
else {
2158+
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags);
2159+
}
21552160
}
21562161
else if (type.flags & TypeFlags.UnionOrIntersection) {
21572162
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags);

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ namespace ts {
327327
}
328328
else {
329329
errorNameNode = declaration.name;
330-
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
330+
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
331331
errorNameNode = undefined;
332332
}
333333
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,7 @@ namespace ts {
19461946
UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
19471947
InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type
19481948
InTypeAlias = 0x00000200, // Writing type in type alias declaration
1949+
UseTypeAliasValue = 0x00000400, // Writing infered type alias as its value. This is used when we emit declaration file
19491950
}
19501951

19511952
export const enum SymbolFormatFlags {

0 commit comments

Comments
 (0)