Skip to content

Commit

Permalink
Only defer aliased array and tuple types
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Aug 27, 2019
1 parent b18c70f commit c2d0aa8
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9614,15 +9614,40 @@ namespace ts {
return getTupleTypeOfArity(node.elementTypes.length, minLength, !!restElement, readonly, /*associatedNames*/ undefined);
}

function isAliasedType(node: Node): boolean {
const parent = node.parent;
switch (parent.kind) {
case SyntaxKind.ParenthesizedType:
case SyntaxKind.ArrayType:
case SyntaxKind.TupleType:
case SyntaxKind.RestType:
case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType:
case SyntaxKind.IndexedAccessType:
return isAliasedType(parent);
case SyntaxKind.TypeAliasDeclaration:
return true;
}
return false;
}

function getTypeFromArrayOrTupleTypeNode(node: ArrayTypeNode | TupleTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
const target = getArrayOrTupleTargetType(node);
const aliasSymbol = getAliasSymbolForTypeNode(node);
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
links.resolvedType = target === emptyGenericType ? emptyObjectType :
node.kind === SyntaxKind.TupleType && node.elementTypes.length === 0 ? target :
createDeferredTypeReference(target, node, /*mapper*/ undefined, aliasSymbol, aliasTypeArguments);
if (target === emptyGenericType) {
links.resolvedType = emptyObjectType;
}
else if (isAliasedType(node)) {
const aliasSymbol = getAliasSymbolForTypeNode(node);
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
links.resolvedType = node.kind === SyntaxKind.TupleType && node.elementTypes.length === 0 ? target :
createDeferredTypeReference(target, node, /*mapper*/ undefined, aliasSymbol, aliasTypeArguments);
}
else {
const elementTypes = node.kind === SyntaxKind.ArrayType ? [getTypeFromTypeNode(node.elementType)] : map(node.elementTypes, getTypeFromTypeNode);
links.resolvedType = createTypeReference(target, elementTypes);
}
}
return links.resolvedType;
}
Expand Down

0 comments on commit c2d0aa8

Please sign in to comment.