More simplification + consistent use of getConstraintOfTypeParameter

This commit is contained in:
Anders Hejlsberg
2018-07-25 10:35:30 -07:00
committed by Mohamed Hegazy
parent a581eae955
commit 483ed8fb50
2 changed files with 6 additions and 15 deletions
+4 -13
View File
@@ -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(<InstantiableType | UnionOrIntersectionType>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;
}
/**
+2 -2
View File
@@ -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 {