(type, writing)
| 62304 | // the type itself if no transformation is possible. The writing flag indicates that the type is |
| 62305 | // the target of an assignment. |
| 62306 | function getSimplifiedIndexedAccessType(type, writing) { |
| 62307 | var cache = writing ? "simplifiedForWriting" : "simplifiedForReading"; |
| 62308 | if (type[cache]) { |
| 62309 | return type[cache] === circularConstraintType ? type : type[cache]; |
| 62310 | } |
| 62311 | type[cache] = circularConstraintType; |
| 62312 | // We recursively simplify the object type as it may in turn be an indexed access type. For example, with |
| 62313 | // '{ [P in T]: { [Q in U]: number } }[T][U]' we want to first simplify the inner indexed access type. |
| 62314 | var objectType = getSimplifiedType(type.objectType, writing); |
| 62315 | var indexType = getSimplifiedType(type.indexType, writing); |
| 62316 | // T[A | B] -> T[A] | T[B] (reading) |
| 62317 | // T[A | B] -> T[A] & T[B] (writing) |
| 62318 | var distributedOverIndex = distributeObjectOverIndexType(objectType, indexType, writing); |
| 62319 | if (distributedOverIndex) { |
| 62320 | return type[cache] = distributedOverIndex; |
| 62321 | } |
| 62322 | // Only do the inner distributions if the index can no longer be instantiated to cause index distribution again |
| 62323 | if (!(indexType.flags & 465829888 /* TypeFlags.Instantiable */)) { |
| 62324 | // (T | U)[K] -> T[K] | U[K] (reading) |
| 62325 | // (T | U)[K] -> T[K] & U[K] (writing) |
| 62326 | // (T & U)[K] -> T[K] & U[K] |
| 62327 | var distributedOverObject = distributeIndexOverObjectType(objectType, indexType, writing); |
| 62328 | if (distributedOverObject) { |
| 62329 | return type[cache] = distributedOverObject; |
| 62330 | } |
| 62331 | } |
| 62332 | // So ultimately (reading): |
| 62333 | // ((A & B) | C)[K1 | K2] -> ((A & B) | C)[K1] | ((A & B) | C)[K2] -> (A & B)[K1] | C[K1] | (A & B)[K2] | C[K2] -> (A[K1] & B[K1]) | C[K1] | (A[K2] & B[K2]) | C[K2] |
| 62334 | // A generic tuple type indexed by a number exists only when the index type doesn't select a |
| 62335 | // fixed element. We simplify to either the combined type of all elements (when the index type |
| 62336 | // the actual number type) or to the combined type of all non-fixed elements. |
| 62337 | if (isGenericTupleType(objectType) && indexType.flags & 296 /* TypeFlags.NumberLike */) { |
| 62338 | var elementType = getElementTypeOfSliceOfTupleType(objectType, indexType.flags & 8 /* TypeFlags.Number */ ? 0 : objectType.target.fixedLength, /*endSkipCount*/ 0, writing); |
| 62339 | if (elementType) { |
| 62340 | return type[cache] = elementType; |
| 62341 | } |
| 62342 | } |
| 62343 | // If the object type is a mapped type { [P in K]: E }, where K is generic, or { [P in K as N]: E }, where |
| 62344 | // K is generic and N is assignable to P, instantiate E using a mapper that substitutes the index type for P. |
| 62345 | // For example, for an index access { [P in K]: Box<T[P]> }[X], we construct the type Box<T[X]>. |
| 62346 | if (isGenericMappedType(objectType)) { |
| 62347 | var nameType = getNameTypeFromMappedType(objectType); |
| 62348 | if (!nameType || isTypeAssignableTo(nameType, getTypeParameterFromMappedType(objectType))) { |
| 62349 | return type[cache] = mapType(substituteIndexedMappedType(objectType, type.indexType), function (t) { return getSimplifiedType(t, writing); }); |
| 62350 | } |
| 62351 | } |
| 62352 | return type[cache] = type; |
| 62353 | } |
| 62354 | function getSimplifiedConditionalType(type, writing) { |
| 62355 | var checkType = type.checkType; |
| 62356 | var extendsType = type.extendsType; |
no test coverage detected
searching dependent graphs…