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

Function checkTypeRelatedTo

test/fixtures/snapshot/typescript.js:64669–66868  ·  view source on GitHub ↗

* Checks if 'source' is related to 'target' (e.g.: is a assignable to). * @param source The left-hand-side of the relation. * @param target The right-hand-side of the relation. * @param relation The relation considered. One of 'identityRelation', 'subtypeRelation', 'assign

(source, target, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer)

Source from the content-addressed store, hash-verified

64667 * @param errorOutputContainer Return the diagnostic. Do not log if 'skipLogging' is truthy.
64668 */
64669 function checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer) {
64670 var errorInfo;
64671 var relatedInfo;
64672 var maybeKeys;
64673 var sourceStack;
64674 var targetStack;
64675 var maybeCount = 0;
64676 var sourceDepth = 0;
64677 var targetDepth = 0;
64678 var expandingFlags = 0 /* ExpandingFlags.None */;
64679 var overflow = false;
64680 var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
64681 var lastSkippedInfo;
64682 var incompatibleStack;
64683 var inPropertyCheck = false;
64684 ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
64685 var result = isRelatedTo(source, target, 3 /* RecursionFlags.Both */, /*reportErrors*/ !!errorNode, headMessage);
64686 if (incompatibleStack) {
64687 reportIncompatibleStack();
64688 }
64689 if (overflow) {
64690 ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* tracing.Phase.CheckTypes */, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth: sourceDepth, targetDepth: targetDepth });
64691 var diag = error(errorNode || currentNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
64692 if (errorOutputContainer) {
64693 (errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
64694 }
64695 }
64696 else if (errorInfo) {
64697 if (containingMessageChain) {
64698 var chain = containingMessageChain();
64699 if (chain) {
64700 ts.concatenateDiagnosticMessageChains(chain, errorInfo);
64701 errorInfo = chain;
64702 }
64703 }
64704 var relatedInformation = void 0;
64705 // Check if we should issue an extra diagnostic to produce a quickfix for a slightly incorrect import statement
64706 if (headMessage && errorNode && !result && source.symbol) {
64707 var links = getSymbolLinks(source.symbol);
64708 if (links.originatingImport && !ts.isImportCall(links.originatingImport)) {
64709 var helpfulRetry = checkTypeRelatedTo(getTypeOfSymbol(links.target), target, relation, /*errorNode*/ undefined);
64710 if (helpfulRetry) {
64711 // Likely an incorrect import. Issue a helpful diagnostic to produce a quickfix to change the import
64712 var diag_1 = ts.createDiagnosticForNode(links.originatingImport, ts.Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead);
64713 relatedInformation = ts.append(relatedInformation, diag_1); // Cause the error to appear with the error that triggered it
64714 }
64715 }
64716 }
64717 var diag = ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, relatedInformation);
64718 if (relatedInfo) {
64719 ts.addRelatedInfo.apply(void 0, __spreadArray([diag], relatedInfo, false));
64720 }
64721 if (errorOutputContainer) {
64722 (errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
64723 }
64724 if (!errorOutputContainer || !errorOutputContainer.skipLogging) {
64725 diagnostics.add(diag);
64726 }

Calls 11

isRelatedToFunction · 0.85
reportIncompatibleStackFunction · 0.85
typeToStringFunction · 0.85
getSymbolLinksFunction · 0.85
getTypeOfSymbolFunction · 0.85
assertMethod · 0.80
errorFunction · 0.70
addMethod · 0.65
pushMethod · 0.45
appendMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…