* Return the resolved base constraint of a type variable. The noConstraintType singleton is returned if the * type variable has no constraint, and the circularConstraintType singleton is returned if the constraint * circularly references the type variable.
(type)
| 58951 | * circularly references the type variable. |
| 58952 | */ |
| 58953 | function getResolvedBaseConstraint(type) { |
| 58954 | if (type.resolvedBaseConstraint) { |
| 58955 | return type.resolvedBaseConstraint; |
| 58956 | } |
| 58957 | var stack = []; |
| 58958 | return type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type); |
| 58959 | function getImmediateBaseConstraint(t) { |
| 58960 | if (!t.immediateBaseConstraint) { |
| 58961 | if (!pushTypeResolution(t, 4 /* TypeSystemPropertyName.ImmediateBaseConstraint */)) { |
| 58962 | return circularConstraintType; |
| 58963 | } |
| 58964 | var result = void 0; |
| 58965 | // We always explore at least 10 levels of nested constraints. Thereafter, we continue to explore |
| 58966 | // up to 50 levels of nested constraints provided there are no "deeply nested" types on the stack |
| 58967 | // (i.e. no types for which five instantiations have been recorded on the stack). If we reach 50 |
| 58968 | // levels of nesting, we are presumably exploring a repeating pattern with a long cycle that hasn't |
| 58969 | // yet triggered the deeply nested limiter. We have no test cases that actually get to 50 levels of |
| 58970 | // nesting, so it is effectively just a safety stop. |
| 58971 | var identity_1 = getRecursionIdentity(t); |
| 58972 | if (stack.length < 10 || stack.length < 50 && !ts.contains(stack, identity_1)) { |
| 58973 | stack.push(identity_1); |
| 58974 | result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false)); |
| 58975 | stack.pop(); |
| 58976 | } |
| 58977 | if (!popTypeResolution()) { |
| 58978 | if (t.flags & 262144 /* TypeFlags.TypeParameter */) { |
| 58979 | var errorNode = getConstraintDeclaration(t); |
| 58980 | if (errorNode) { |
| 58981 | var diagnostic = error(errorNode, ts.Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(t)); |
| 58982 | if (currentNode && !ts.isNodeDescendantOf(errorNode, currentNode) && !ts.isNodeDescendantOf(currentNode, errorNode)) { |
| 58983 | ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(currentNode, ts.Diagnostics.Circularity_originates_in_type_at_this_location)); |
| 58984 | } |
| 58985 | } |
| 58986 | } |
| 58987 | result = circularConstraintType; |
| 58988 | } |
| 58989 | t.immediateBaseConstraint = result || noConstraintType; |
| 58990 | } |
| 58991 | return t.immediateBaseConstraint; |
| 58992 | } |
| 58993 | function getBaseConstraint(t) { |
| 58994 | var c = getImmediateBaseConstraint(t); |
| 58995 | return c !== noConstraintType && c !== circularConstraintType ? c : undefined; |
| 58996 | } |
| 58997 | function computeBaseConstraint(t) { |
| 58998 | if (t.flags & 262144 /* TypeFlags.TypeParameter */) { |
| 58999 | var constraint = getConstraintFromTypeParameter(t); |
| 59000 | return t.isThisType || !constraint ? |
| 59001 | constraint : |
| 59002 | getBaseConstraint(constraint); |
| 59003 | } |
| 59004 | if (t.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { |
| 59005 | var types = t.types; |
| 59006 | var baseTypes = []; |
| 59007 | var different = false; |
| 59008 | for (var _i = 0, types_7 = types; _i < types_7.length; _i++) { |
| 59009 | var type_4 = types_7[_i]; |
| 59010 | var baseType = getBaseConstraint(type_4); |
no test coverage detected
searching dependent graphs…