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

Function isKnownProperty

test/fixtures/snapshot/typescript.js:74269–74291  ·  view source on GitHub ↗

* Check if a property with the given name is known anywhere in the given type. In an object type, a property * is considered known if * 1. the object type is empty and the check is for assignability, or * 2. if the object type has index signatures, or * 3. if the

(targetType, name, isComparingJsxAttributes)

Source from the content-addressed store, hash-verified

74267 * @param isComparingJsxAttributes a boolean flag indicating whether we are searching in JsxAttributesType
74268 */
74269 function isKnownProperty(targetType, name, isComparingJsxAttributes) {
74270 if (targetType.flags & 524288 /* TypeFlags.Object */) {
74271 // For backwards compatibility a symbol-named property is satisfied by a string index signature. This
74272 // is incorrect and inconsistent with element access expressions, where it is an error, so eventually
74273 // we should remove this exception.
74274 if (getPropertyOfObjectType(targetType, name) ||
74275 getApplicableIndexInfoForName(targetType, name) ||
74276 isLateBoundName(name) && getIndexInfoOfType(targetType, stringType) ||
74277 isComparingJsxAttributes && isHyphenatedJsxName(name)) {
74278 // For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known.
74279 return true;
74280 }
74281 }
74282 else if (targetType.flags & 3145728 /* TypeFlags.UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
74283 for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
74284 var t = _a[_i];
74285 if (isKnownProperty(t, name, isComparingJsxAttributes)) {
74286 return true;
74287 }
74288 }
74289 }
74290 return false;
74291 }
74292 function isExcessPropertyCheckTarget(type) {
74293 return !!(type.flags & 524288 /* TypeFlags.Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectFlags.ObjectLiteralPatternWithComputedProperties */) ||
74294 type.flags & 67108864 /* TypeFlags.NonPrimitive */ ||

Callers 2

_loop_19Function · 0.85
hasCommonPropertiesFunction · 0.85

Calls 6

getPropertyOfObjectTypeFunction · 0.85
isLateBoundNameFunction · 0.85
getIndexInfoOfTypeFunction · 0.85
isHyphenatedJsxNameFunction · 0.85

Tested by

no test coverage detected