Skip to content

Commit 7945eb6

Browse files
author
Kanchalai Tanglertsampan
committed
Only emit inferred type-alias if it is fully instantiated
1 parent 60ab007 commit 7945eb6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,9 +2182,14 @@ namespace ts {
21822182
// The specified symbol flags need to be reinterpreted as type flags
21832183
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
21842184
}
2185-
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
2185+
else if (!(flags & TypeFormatFlags.InTypeAlias) && ((type.flags & TypeFlags.Anonymous && !(<AnonymousType>type).target) || type.flags & TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
21862186
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
2187-
// Only write out inferred type with its corresponding type-alias if type-alias is visible
2187+
// We emit inferred type as type-alias at the current localtion if all the following is true
2188+
// the input type is has alias symbol that is accessible
2189+
// the input type is a union, intersection or anonymous type that is fully instantiated (if not we want to keep dive into)
2190+
// e.g.: export type Bar<X, Y> = () => [X, Y];
2191+
// export type Foo<Y> = Bar<any, Y>;
2192+
// export const y = (x: Foo<string>) => 1 // we want to emit as ...x: () => [any, string])
21882193
const typeArguments = type.aliasTypeArguments;
21892194
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
21902195
}

0 commit comments

Comments
 (0)