From 483ed8fb5049be4dcc89ef5e79b66e013139c21a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 24 Jul 2018 15:27:39 -0700 Subject: [PATCH] More simplification + consistent use of getConstraintOfTypeParameter --- src/compiler/checker.ts | 17 ++++------------- src/compiler/symbolWalker.ts | 4 ++-- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ff65929d52a..3ee66280aeb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -250,7 +250,7 @@ namespace ts { getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, - getConstraintFromTypeParameter, + getConstraintOfTypeParameter, getFirstIdentifier, ), getAmbientModules, @@ -6930,21 +6930,12 @@ namespace ts { return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type: Type) { + function getBaseConstraintOfType(type: Type): Type | undefined { if (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.UnionOrIntersection)) { const constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - - function getBaseConstraintOfType(type: Type): Type | undefined { - const constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & TypeFlags.Index) { - return keyofConstraintType; - } - return constraint; + return type.flags & TypeFlags.Index ? keyofConstraintType : undefined; } /** diff --git a/src/compiler/symbolWalker.ts b/src/compiler/symbolWalker.ts index cce6739d359..1f6930076be 100644 --- a/src/compiler/symbolWalker.ts +++ b/src/compiler/symbolWalker.ts @@ -9,7 +9,7 @@ namespace ts { getTypeOfSymbol: (sym: Symbol) => Type, getResolvedSymbol: (node: Node) => Symbol, getIndexTypeOfStructuredType: (type: Type, kind: IndexKind) => Type | undefined, - getConstraintFromTypeParameter: (typeParameter: TypeParameter) => Type | undefined, + getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined, getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier) { return getSymbolWalker; @@ -93,7 +93,7 @@ namespace ts { } function visitTypeParameter(type: TypeParameter): void { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type: UnionOrIntersectionType): void {