MCPcopy Index your code
hub / github.com/nodejs/node / computeBaseConstraint

Function computeBaseConstraint

test/fixtures/snapshot/typescript.js:58997–59059  ·  view source on GitHub ↗
(t)

Source from the content-addressed store, hash-verified

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);
59011 if (baseType) {
59012 if (baseType !== type_4) {
59013 different = true;
59014 }
59015 baseTypes.push(baseType);
59016 }
59017 else {
59018 different = true;
59019 }
59020 }
59021 if (!different) {
59022 return t;
59023 }
59024 return t.flags & 1048576 /* TypeFlags.Union */ && baseTypes.length === types.length ? getUnionType(baseTypes) :
59025 t.flags & 2097152 /* TypeFlags.Intersection */ && baseTypes.length ? getIntersectionType(baseTypes) :
59026 undefined;
59027 }
59028 if (t.flags & 4194304 /* TypeFlags.Index */) {
59029 return keyofConstraintType;
59030 }
59031 if (t.flags & 134217728 /* TypeFlags.TemplateLiteral */) {
59032 var types = t.types;
59033 var constraints = ts.mapDefined(types, getBaseConstraint);
59034 return constraints.length === types.length ? getTemplateLiteralType(t.texts, constraints) : stringType;
59035 }
59036 if (t.flags & 268435456 /* TypeFlags.StringMapping */) {
59037 var constraint = getBaseConstraint(t.type);
59038 return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
59039 }
59040 if (t.flags & 8388608 /* TypeFlags.IndexedAccess */) {
59041 if (isMappedTypeGenericIndexedAccess(t)) {
59042 // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
59043 // we substitute an instantiation of E where P is replaced with X.
59044 return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
59045 }
59046 var baseObjectType = getBaseConstraint(t.objectType);
59047 var baseIndexType = getBaseConstraint(t.indexType);
59048 var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
59049 return baseIndexedAccess && getBaseConstraint(baseIndexedAccess);
59050 }
59051 if (t.flags & 16777216 /* TypeFlags.Conditional */) {
59052 var constraint = getConstraintFromConditionalType(t);
59053 return constraint && getBaseConstraint(constraint);
59054 }

Callers 1

Calls 11

getBaseConstraintFunction · 0.85
getUnionTypeFunction · 0.85
getIntersectionTypeFunction · 0.85
getTemplateLiteralTypeFunction · 0.85
getStringMappingTypeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…