mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Simplify logic in getBaseConstraint
This commit is contained in:
@@ -4370,8 +4370,7 @@ namespace ts {
|
||||
case TypeSystemPropertyName.ResolvedReturnType:
|
||||
return !!(<Signature>target).resolvedReturnType;
|
||||
case TypeSystemPropertyName.ImmediateBaseConstraint:
|
||||
const bc = (<Type>target).immediateBaseConstraint;
|
||||
return !!bc && bc !== circularConstraintType;
|
||||
return !!(<Type>target).immediateBaseConstraint;
|
||||
}
|
||||
return Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
|
||||
}
|
||||
@@ -6987,30 +6986,26 @@ namespace ts {
|
||||
* circularly references the type variable.
|
||||
*/
|
||||
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
|
||||
let circular: boolean | undefined;
|
||||
if (!type.resolvedBaseConstraint) {
|
||||
const constraint = getBaseConstraint(type);
|
||||
type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
|
||||
return type.resolvedBaseConstraint ||
|
||||
(type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type));
|
||||
|
||||
function getImmediateBaseConstraint(t: Type): Type {
|
||||
if (!t.immediateBaseConstraint) {
|
||||
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
|
||||
return circularConstraintType;
|
||||
}
|
||||
let result = computeBaseConstraint(getSimplifiedType(t));
|
||||
if (!popTypeResolution()) {
|
||||
result = circularConstraintType;
|
||||
}
|
||||
t.immediateBaseConstraint = result || noConstraintType;
|
||||
}
|
||||
return t.immediateBaseConstraint;
|
||||
}
|
||||
return type.resolvedBaseConstraint;
|
||||
|
||||
function getBaseConstraint(t: Type): Type | undefined {
|
||||
if (t.immediateBaseConstraint) {
|
||||
return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint;
|
||||
}
|
||||
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
|
||||
circular = true;
|
||||
t.immediateBaseConstraint = circularConstraintType;
|
||||
return undefined;
|
||||
}
|
||||
const result = computeBaseConstraint(getSimplifiedType(t));
|
||||
if (!popTypeResolution()) {
|
||||
circular = true;
|
||||
t.immediateBaseConstraint = circularConstraintType;
|
||||
return undefined;
|
||||
}
|
||||
t.immediateBaseConstraint = !result ? noConstraintType : result;
|
||||
return result;
|
||||
const c = getImmediateBaseConstraint(t);
|
||||
return c !== noConstraintType && c !== circularConstraintType ? c : undefined;
|
||||
}
|
||||
|
||||
function computeBaseConstraint(t: Type): Type | undefined {
|
||||
|
||||
Reference in New Issue
Block a user