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

Function reportRelationError

test/fixtures/snapshot/typescript.js:64876–64925  ·  view source on GitHub ↗
(message, source, target)

Source from the content-addressed store, hash-verified

64874 }
64875 }
64876 function reportRelationError(message, source, target) {
64877 if (incompatibleStack)
64878 reportIncompatibleStack();
64879 var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
64880 var generalizedSource = source;
64881 var generalizedSourceType = sourceType;
64882 if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
64883 generalizedSource = getBaseTypeOfLiteralType(source);
64884 ts.Debug.assert(!isTypeAssignableTo(generalizedSource, target), "generalized source shouldn't be assignable");
64885 generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
64886 }
64887 if (target.flags & 262144 /* TypeFlags.TypeParameter */ && target !== markerSuperType && target !== markerSubType) {
64888 var constraint = getBaseConstraintOfType(target);
64889 var needsOriginalSource = void 0;
64890 if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
64891 reportError(ts.Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2, needsOriginalSource ? sourceType : generalizedSourceType, targetType, typeToString(constraint));
64892 }
64893 else {
64894 errorInfo = undefined;
64895 reportError(ts.Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1, targetType, generalizedSourceType);
64896 }
64897 }
64898 if (!message) {
64899 if (relation === comparableRelation) {
64900 message = ts.Diagnostics.Type_0_is_not_comparable_to_type_1;
64901 }
64902 else if (sourceType === targetType) {
64903 message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated;
64904 }
64905 else if (exactOptionalPropertyTypes && getExactOptionalUnassignableProperties(source, target).length) {
64906 message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties;
64907 }
64908 else {
64909 if (source.flags & 128 /* TypeFlags.StringLiteral */ && target.flags & 1048576 /* TypeFlags.Union */) {
64910 var suggestedType = getSuggestedTypeForNonexistentStringLiteralType(source, target);
64911 if (suggestedType) {
64912 reportError(ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Did_you_mean_2, generalizedSourceType, targetType, typeToString(suggestedType));
64913 return;
64914 }
64915 }
64916 message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1;
64917 }
64918 }
64919 else if (message === ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1
64920 && exactOptionalPropertyTypes
64921 && getExactOptionalUnassignableProperties(source, target).length) {
64922 message = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties;
64923 }
64924 reportError(message, generalizedSourceType, targetType);
64925 }
64926 function tryElaborateErrorsForPrimitivesAndObjects(source, target) {
64927 var sourceType = symbolValueDeclarationIsContextSensitive(source.symbol) ? typeToString(source, source.symbol.valueDeclaration) : typeToString(source);
64928 var targetType = symbolValueDeclarationIsContextSensitive(target.symbol) ? typeToString(target, target.symbol.valueDeclaration) : typeToString(target);

Callers 2

isRelatedToFunction · 0.85
reportErrorResultsFunction · 0.85

Calls 13

reportIncompatibleStackFunction · 0.85
isLiteralTypeFunction · 0.85
getBaseTypeOfLiteralTypeFunction · 0.85
isTypeAssignableToFunction · 0.85
getBaseConstraintOfTypeFunction · 0.85
reportErrorFunction · 0.85
typeToStringFunction · 0.85

Tested by

no test coverage detected