(objectType, indexType, accessFlags, accessNode, aliasSymbol, aliasTypeArguments)
| 62403 | }); |
| 62404 | } |
| 62405 | function getIndexedAccessTypeOrUndefined(objectType, indexType, accessFlags, accessNode, aliasSymbol, aliasTypeArguments) { |
| 62406 | if (accessFlags === void 0) { accessFlags = 0 /* AccessFlags.None */; } |
| 62407 | if (objectType === wildcardType || indexType === wildcardType) { |
| 62408 | return wildcardType; |
| 62409 | } |
| 62410 | // If the object type has a string index signature and no other members we know that the result will |
| 62411 | // always be the type of that index signature and we can simplify accordingly. |
| 62412 | if (isStringIndexSignatureOnlyType(objectType) && !(indexType.flags & 98304 /* TypeFlags.Nullable */) && isTypeAssignableToKind(indexType, 4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */)) { |
| 62413 | indexType = stringType; |
| 62414 | } |
| 62415 | // In noUncheckedIndexedAccess mode, indexed access operations that occur in an expression in a read position and resolve to |
| 62416 | // an index signature have 'undefined' included in their type. |
| 62417 | if (compilerOptions.noUncheckedIndexedAccess && accessFlags & 32 /* AccessFlags.ExpressionPosition */) |
| 62418 | accessFlags |= 1 /* AccessFlags.IncludeUndefined */; |
| 62419 | // If the index type is generic, or if the object type is generic and doesn't originate in an expression and |
| 62420 | // the operation isn't exclusively indexing the fixed (non-variadic) portion of a tuple type, we are performing |
| 62421 | // a higher-order index access where we cannot meaningfully access the properties of the object type. Note that |
| 62422 | // for a generic T and a non-generic K, we eagerly resolve T[K] if it originates in an expression. This is to |
| 62423 | // preserve backwards compatibility. For example, an element access 'this["foo"]' has always been resolved |
| 62424 | // eagerly using the constraint type of 'this' at the given location. |
| 62425 | if (isGenericIndexType(indexType) || (accessNode && accessNode.kind !== 194 /* SyntaxKind.IndexedAccessType */ ? |
| 62426 | isGenericTupleType(objectType) && !indexTypeLessThan(indexType, objectType.target.fixedLength) : |
| 62427 | isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, objectType.target.fixedLength)))) { |
| 62428 | if (objectType.flags & 3 /* TypeFlags.AnyOrUnknown */) { |
| 62429 | return objectType; |
| 62430 | } |
| 62431 | // Defer the operation by creating an indexed access type. |
| 62432 | var persistentAccessFlags = accessFlags & 1 /* AccessFlags.Persistent */; |
| 62433 | var id = objectType.id + "," + indexType.id + "," + persistentAccessFlags + getAliasId(aliasSymbol, aliasTypeArguments); |
| 62434 | var type = indexedAccessTypes.get(id); |
| 62435 | if (!type) { |
| 62436 | indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, persistentAccessFlags, aliasSymbol, aliasTypeArguments)); |
| 62437 | } |
| 62438 | return type; |
| 62439 | } |
| 62440 | // In the following we resolve T[K] to the type of the property in T selected by K. |
| 62441 | // We treat boolean as different from other unions to improve errors; |
| 62442 | // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. |
| 62443 | var apparentObjectType = getReducedApparentType(objectType); |
| 62444 | if (indexType.flags & 1048576 /* TypeFlags.Union */ && !(indexType.flags & 16 /* TypeFlags.Boolean */)) { |
| 62445 | var propTypes = []; |
| 62446 | var wasMissingProp = false; |
| 62447 | for (var _i = 0, _a = indexType.types; _i < _a.length; _i++) { |
| 62448 | var t = _a[_i]; |
| 62449 | var propType = getPropertyTypeForIndexType(objectType, apparentObjectType, t, indexType, accessNode, accessFlags | (wasMissingProp ? 128 /* AccessFlags.SuppressNoImplicitAnyError */ : 0)); |
| 62450 | if (propType) { |
| 62451 | propTypes.push(propType); |
| 62452 | } |
| 62453 | else if (!accessNode) { |
| 62454 | // If there's no error node, we can immeditely stop, since error reporting is off |
| 62455 | return undefined; |
| 62456 | } |
| 62457 | else { |
| 62458 | // Otherwise we set a flag and return at the end of the loop so we still mark all errors |
| 62459 | wasMissingProp = true; |
| 62460 | } |
| 62461 | } |
| 62462 | if (wasMissingProp) { |
no test coverage detected