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

Function checkIndexConstraintForProperty

test/fixtures/snapshot/typescript.js:83837–83862  ·  view source on GitHub ↗
(type, prop, propNameType, propType)

Source from the content-addressed store, hash-verified

83835 }
83836 }
83837 function checkIndexConstraintForProperty(type, prop, propNameType, propType) {
83838 var declaration = prop.valueDeclaration;
83839 var name = ts.getNameOfDeclaration(declaration);
83840 if (name && ts.isPrivateIdentifier(name)) {
83841 return;
83842 }
83843 var indexInfos = getApplicableIndexInfos(type, propNameType);
83844 var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* ObjectFlags.Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* SyntaxKind.InterfaceDeclaration */) : undefined;
83845 var localPropDeclaration = declaration && declaration.kind === 221 /* SyntaxKind.BinaryExpression */ ||
83846 name && name.kind === 162 /* SyntaxKind.ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
83847 var _loop_28 = function (info) {
83848 var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
83849 // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
83850 // in the containing type, or (c) the containing type is an interface and no base interface contains both the property and
83851 // the index signature (i.e. property and index signature are declared in separate inherited interfaces).
83852 var errorNode = localPropDeclaration || localIndexDeclaration ||
83853 (interfaceDeclaration && !ts.some(getBaseTypes(type), function (base) { return !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType); }) ? interfaceDeclaration : undefined);
83854 if (errorNode && !isTypeAssignableTo(propType, info.type)) {
83855 error(errorNode, ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
83856 }
83857 };
83858 for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
83859 var info = indexInfos_9[_i];
83860 _loop_28(info);
83861 }
83862 }
83863 function checkIndexConstraintForIndexSignature(type, checkInfo) {
83864 var declaration = checkInfo.declaration;
83865 var indexInfos = getApplicableIndexInfos(type, checkInfo.keyType);

Callers 1

checkIndexConstraintsFunction · 0.85

Calls 3

getApplicableIndexInfosFunction · 0.85
getParentOfSymbolFunction · 0.85
_loop_28Function · 0.85

Tested by

no test coverage detected