diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1366745c3..e7d26d1eab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -249,7 +249,7 @@ namespace ts { getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, - getConstraintFromTypeParameter, + getConstraintOfTypeParameter, getFirstIdentifier, ), getAmbientModules, @@ -6951,21 +6951,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 cce6739d35..1f6930076b 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 {