MCPcopy Create free account
hub / github.com/nodejs/node / hasExcessProperties

Function hasExcessProperties

test/fixtures/snapshot/typescript.js:65178–65262  ·  view source on GitHub ↗
(source, target, reportErrors)

Source from the content-addressed store, hash-verified

65176 return getUnionType(ts.reduceLeft(types, appendPropType, /*initial*/ undefined) || ts.emptyArray);
65177 }
65178 function hasExcessProperties(source, target, reportErrors) {
65179 var _a;
65180 if (!isExcessPropertyCheckTarget(target) || !noImplicitAny && ts.getObjectFlags(target) & 4096 /* ObjectFlags.JSLiteral */) {
65181 return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
65182 }
65183 var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* ObjectFlags.JsxAttributes */);
65184 if ((relation === assignableRelation || relation === comparableRelation) &&
65185 (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
65186 return false;
65187 }
65188 var reducedTarget = target;
65189 var checkTypes;
65190 if (target.flags & 1048576 /* TypeFlags.Union */) {
65191 reducedTarget = findMatchingDiscriminantType(source, target, isRelatedTo) || filterPrimitivesIfContainsNonPrimitive(target);
65192 checkTypes = reducedTarget.flags & 1048576 /* TypeFlags.Union */ ? reducedTarget.types : [reducedTarget];
65193 }
65194 var _loop_19 = function (prop) {
65195 if (shouldCheckAsExcessProperty(prop, source.symbol) && !isIgnoredJsxProperty(source, prop)) {
65196 if (!isKnownProperty(reducedTarget, prop.escapedName, isComparingJsxAttributes)) {
65197 if (reportErrors) {
65198 // Report error in terms of object types in the target as those are the only ones
65199 // we check in isKnownProperty.
65200 var errorTarget = filterType(reducedTarget, isExcessPropertyCheckTarget);
65201 // We know *exactly* where things went wrong when comparing the types.
65202 // Use this property as the error node as this will be more helpful in
65203 // reasoning about what went wrong.
65204 if (!errorNode)
65205 return { value: ts.Debug.fail() };
65206 if (ts.isJsxAttributes(errorNode) || ts.isJsxOpeningLikeElement(errorNode) || ts.isJsxOpeningLikeElement(errorNode.parent)) {
65207 // JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
65208 // However, using an object-literal error message will be very confusing to the users so we give different a message.
65209 if (prop.valueDeclaration && ts.isJsxAttribute(prop.valueDeclaration) && ts.getSourceFileOfNode(errorNode) === ts.getSourceFileOfNode(prop.valueDeclaration.name)) {
65210 // Note that extraneous children (as in `<NoChild>extra</NoChild>`) don't pass this check,
65211 // since `children` is a SyntaxKind.PropertySignature instead of a SyntaxKind.JsxAttribute.
65212 errorNode = prop.valueDeclaration.name;
65213 }
65214 var propName = symbolToString(prop);
65215 var suggestionSymbol = getSuggestedSymbolForNonexistentJSXAttribute(propName, errorTarget);
65216 var suggestion = suggestionSymbol ? symbolToString(suggestionSymbol) : undefined;
65217 if (suggestion) {
65218 reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName, typeToString(errorTarget), suggestion);
65219 }
65220 else {
65221 reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, propName, typeToString(errorTarget));
65222 }
65223 }
65224 else {
65225 // use the property's value declaration if the property is assigned inside the literal itself
65226 var objectLiteralDeclaration_1 = ((_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) && ts.firstOrUndefined(source.symbol.declarations);
65227 var suggestion = void 0;
65228 if (prop.valueDeclaration && ts.findAncestor(prop.valueDeclaration, function (d) { return d === objectLiteralDeclaration_1; }) && ts.getSourceFileOfNode(objectLiteralDeclaration_1) === ts.getSourceFileOfNode(errorNode)) {
65229 var propDeclaration = prop.valueDeclaration;
65230 ts.Debug.assertNode(propDeclaration, ts.isObjectLiteralElementLike);
65231 errorNode = propDeclaration;
65232 var name = propDeclaration.name;
65233 if (ts.isIdentifier(name)) {
65234 suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
65235 }

Callers 1

isRelatedToFunction · 0.85

Calls 7

isTypeSubsetOfFunction · 0.85
isEmptyObjectTypeFunction · 0.85
getPropertiesOfTypeFunction · 0.85
_loop_19Function · 0.85

Tested by

no test coverage detected