Skip to content

Commit 7233cde

Browse files
committed
Simplify logic in getBaseConstraint
1 parent 06a1145 commit 7233cde

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,8 +4370,7 @@ namespace ts {
43704370
case TypeSystemPropertyName.ResolvedReturnType:
43714371
return !!(<Signature>target).resolvedReturnType;
43724372
case TypeSystemPropertyName.ImmediateBaseConstraint:
4373-
const bc = (<Type>target).immediateBaseConstraint;
4374-
return !!bc && bc !== circularConstraintType;
4373+
return !!(<Type>target).immediateBaseConstraint;
43754374
}
43764375
return Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
43774376
}
@@ -6987,30 +6986,26 @@ namespace ts {
69876986
* circularly references the type variable.
69886987
*/
69896988
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
6990-
let circular: boolean | undefined;
6991-
if (!type.resolvedBaseConstraint) {
6992-
const constraint = getBaseConstraint(type);
6993-
type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
6989+
return type.resolvedBaseConstraint ||
6990+
(type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type));
6991+
6992+
function getImmediateBaseConstraint(t: Type): Type {
6993+
if (!t.immediateBaseConstraint) {
6994+
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
6995+
return circularConstraintType;
6996+
}
6997+
let result = computeBaseConstraint(getSimplifiedType(t));
6998+
if (!popTypeResolution()) {
6999+
result = circularConstraintType;
7000+
}
7001+
t.immediateBaseConstraint = result || noConstraintType;
7002+
}
7003+
return t.immediateBaseConstraint;
69947004
}
6995-
return type.resolvedBaseConstraint;
69967005

69977006
function getBaseConstraint(t: Type): Type | undefined {
6998-
if (t.immediateBaseConstraint) {
6999-
return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint;
7000-
}
7001-
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
7002-
circular = true;
7003-
t.immediateBaseConstraint = circularConstraintType;
7004-
return undefined;
7005-
}
7006-
const result = computeBaseConstraint(getSimplifiedType(t));
7007-
if (!popTypeResolution()) {
7008-
circular = true;
7009-
t.immediateBaseConstraint = circularConstraintType;
7010-
return undefined;
7011-
}
7012-
t.immediateBaseConstraint = !result ? noConstraintType : result;
7013-
return result;
7007+
const c = getImmediateBaseConstraint(t);
7008+
return c !== noConstraintType && c !== circularConstraintType ? c : undefined;
70147009
}
70157010

70167011
function computeBaseConstraint(t: Type): Type | undefined {

0 commit comments

Comments
 (0)