Don't re-alias top-level type aliases with local type aliases (#43701)

* No re-aliasing of top-level type aliases with local type aliases

* Accept new baselines
This commit is contained in:
Anders Hejlsberg
2021-04-17 04:07:46 -10:00
committed by GitHub
parent 01264ac414
commit 0f2dabcd4b
3 changed files with 18 additions and 8 deletions

View File

@@ -12834,12 +12834,22 @@ namespace ts {
typeParameters.length);
return errorType;
}
// We refrain from associating a local type alias with an instantiation of a top-level type alias
// because the local alias may end up being referenced in an inferred return type where it is not
// accessible--which in turn may lead to a large structural expansion of the type when generating
// a .d.ts file. See #43622 for an example.
const aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
const newAliasSymbol = aliasSymbol && (isLocalTypeAlias(symbol) || !isLocalTypeAlias(aliasSymbol)) ? aliasSymbol : undefined;
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), newAliasSymbol, getTypeArgumentsForAliasSymbol(newAliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function isLocalTypeAlias(symbol: Symbol) {
const declaration = symbol.declarations?.find(isTypeAlias);
return !!(declaration && getContainingFunction(declaration));
}
function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined {
switch (node.kind) {
case SyntaxKind.TypeReference: