* For every element returned from the iterator, checks that element to issue an error on a property of that element's type * If that element would issue an error, we first attempt to dive into that element's inner expression and issue a more specific error by recuring into `elaborateError`
(iterator, source, target, relation, containingMessageChain, errorOutputContainer)
| 64012 | * Otherwise, we issue an error on _every_ element which fail the assignability check |
| 64013 | */ |
| 64014 | function elaborateElementwise(iterator, source, target, relation, containingMessageChain, errorOutputContainer) { |
| 64015 | // Assignability failure - check each prop individually, and if that fails, fall back on the bad error span |
| 64016 | var reportedError = false; |
| 64017 | for (var status = iterator.next(); !status.done; status = iterator.next()) { |
| 64018 | var _a = status.value, prop = _a.errorNode, next = _a.innerExpression, nameType = _a.nameType, errorMessage = _a.errorMessage; |
| 64019 | var targetPropType = getBestMatchIndexedAccessTypeOrUndefined(source, target, nameType); |
| 64020 | if (!targetPropType || targetPropType.flags & 8388608 /* TypeFlags.IndexedAccess */) |
| 64021 | continue; // Don't elaborate on indexes on generic variables |
| 64022 | var sourcePropType = getIndexedAccessTypeOrUndefined(source, nameType); |
| 64023 | if (!sourcePropType) |
| 64024 | continue; |
| 64025 | var propName = getPropertyNameFromIndex(nameType, /*accessNode*/ undefined); |
| 64026 | if (!checkTypeRelatedTo(sourcePropType, targetPropType, relation, /*errorNode*/ undefined)) { |
| 64027 | var elaborated = next && elaborateError(next, sourcePropType, targetPropType, relation, /*headMessage*/ undefined, containingMessageChain, errorOutputContainer); |
| 64028 | reportedError = true; |
| 64029 | if (!elaborated) { |
| 64030 | // Issue error on the prop itself, since the prop couldn't elaborate the error |
| 64031 | var resultObj = errorOutputContainer || {}; |
| 64032 | // Use the expression type, if available |
| 64033 | var specificSource = next ? checkExpressionForMutableLocationWithContextualType(next, sourcePropType) : sourcePropType; |
| 64034 | if (exactOptionalPropertyTypes && isExactOptionalPropertyMismatch(specificSource, targetPropType)) { |
| 64035 | var diag = ts.createDiagnosticForNode(prop, ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target, typeToString(specificSource), typeToString(targetPropType)); |
| 64036 | diagnostics.add(diag); |
| 64037 | resultObj.errors = [diag]; |
| 64038 | } |
| 64039 | else { |
| 64040 | var targetIsOptional = !!(propName && (getPropertyOfType(target, propName) || unknownSymbol).flags & 16777216 /* SymbolFlags.Optional */); |
| 64041 | var sourceIsOptional = !!(propName && (getPropertyOfType(source, propName) || unknownSymbol).flags & 16777216 /* SymbolFlags.Optional */); |
| 64042 | targetPropType = removeMissingType(targetPropType, targetIsOptional); |
| 64043 | sourcePropType = removeMissingType(sourcePropType, targetIsOptional && sourceIsOptional); |
| 64044 | var result = checkTypeRelatedTo(specificSource, targetPropType, relation, prop, errorMessage, containingMessageChain, resultObj); |
| 64045 | if (result && specificSource !== sourcePropType) { |
| 64046 | // If for whatever reason the expression type doesn't yield an error, make sure we still issue an error on the sourcePropType |
| 64047 | checkTypeRelatedTo(sourcePropType, targetPropType, relation, prop, errorMessage, containingMessageChain, resultObj); |
| 64048 | } |
| 64049 | } |
| 64050 | if (resultObj.errors) { |
| 64051 | var reportedDiag = resultObj.errors[resultObj.errors.length - 1]; |
| 64052 | var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined; |
| 64053 | var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined; |
| 64054 | var issuedElaboration = false; |
| 64055 | if (!targetProp) { |
| 64056 | var indexInfo = getApplicableIndexInfo(target, nameType); |
| 64057 | if (indexInfo && indexInfo.declaration && !ts.getSourceFileOfNode(indexInfo.declaration).hasNoDefaultLib) { |
| 64058 | issuedElaboration = true; |
| 64059 | ts.addRelatedInfo(reportedDiag, ts.createDiagnosticForNode(indexInfo.declaration, ts.Diagnostics.The_expected_type_comes_from_this_index_signature)); |
| 64060 | } |
| 64061 | } |
| 64062 | if (!issuedElaboration && (targetProp && ts.length(targetProp.declarations) || target.symbol && ts.length(target.symbol.declarations))) { |
| 64063 | var targetNode = targetProp && ts.length(targetProp.declarations) ? targetProp.declarations[0] : target.symbol.declarations[0]; |
| 64064 | if (!ts.getSourceFileOfNode(targetNode).hasNoDefaultLib) { |
| 64065 | ts.addRelatedInfo(reportedDiag, ts.createDiagnosticForNode(targetNode, ts.Diagnostics.The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1, propertyName && !(nameType.flags & 8192 /* TypeFlags.UniqueESSymbol */) ? ts.unescapeLeadingUnderscores(propertyName) : typeToString(nameType), typeToString(target))); |
| 64066 | } |
| 64067 | } |
| 64068 | } |
| 64069 | } |
| 64070 | } |
| 64071 | } |
no test coverage detected