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

Function getPropertyTypeForIndexType

test/fixtures/snapshot/typescript.js:62077–62241  ·  view source on GitHub ↗
(originalObjectType, objectType, indexType, fullIndexType, accessNode, accessFlags)

Source from the content-addressed store, hash-verified

62075 return true;
62076 }
62077 function getPropertyTypeForIndexType(originalObjectType, objectType, indexType, fullIndexType, accessNode, accessFlags) {
62078 var _a;
62079 var accessExpression = accessNode && accessNode.kind === 207 /* SyntaxKind.ElementAccessExpression */ ? accessNode : undefined;
62080 var propName = accessNode && ts.isPrivateIdentifier(accessNode) ? undefined : getPropertyNameFromIndex(indexType, accessNode);
62081 if (propName !== undefined) {
62082 if (accessFlags & 256 /* AccessFlags.Contextual */) {
62083 return getTypeOfPropertyOfContextualType(objectType, propName) || anyType;
62084 }
62085 var prop = getPropertyOfType(objectType, propName);
62086 if (prop) {
62087 if (accessFlags & 64 /* AccessFlags.ReportDeprecated */ && accessNode && prop.declarations && isDeprecatedSymbol(prop) && isUncalledFunctionReference(accessNode, prop)) {
62088 var deprecatedNode = (_a = accessExpression === null || accessExpression === void 0 ? void 0 : accessExpression.argumentExpression) !== null && _a !== void 0 ? _a : (ts.isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode);
62089 addDeprecatedSuggestion(deprecatedNode, prop.declarations, propName);
62090 }
62091 if (accessExpression) {
62092 markPropertyAsReferenced(prop, accessExpression, isSelfTypeAccess(accessExpression.expression, objectType.symbol));
62093 if (isAssignmentToReadonlyEntity(accessExpression, prop, ts.getAssignmentTargetKind(accessExpression))) {
62094 error(accessExpression.argumentExpression, ts.Diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, symbolToString(prop));
62095 return undefined;
62096 }
62097 if (accessFlags & 8 /* AccessFlags.CacheSymbol */) {
62098 getNodeLinks(accessNode).resolvedSymbol = prop;
62099 }
62100 if (isThisPropertyAccessInConstructor(accessExpression, prop)) {
62101 return autoType;
62102 }
62103 }
62104 var propType = getTypeOfSymbol(prop);
62105 return accessExpression && ts.getAssignmentTargetKind(accessExpression) !== 1 /* AssignmentKind.Definite */ ?
62106 getFlowTypeOfReference(accessExpression, propType) :
62107 propType;
62108 }
62109 if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62110 if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* AccessFlags.NoTupleBoundsCheck */)) {
62111 var indexNode = getIndexNodeForAccessExpression(accessNode);
62112 if (isTupleType(objectType)) {
62113 error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62114 }
62115 else {
62116 error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62117 }
62118 }
62119 errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62120 return mapType(objectType, function (t) {
62121 var restType = getRestTypeOfTupleType(t) || undefinedType;
62122 return accessFlags & 1 /* AccessFlags.IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62123 });
62124 }
62125 }
62126 if (!(indexType.flags & 98304 /* TypeFlags.Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* TypeFlags.StringLike */ | 296 /* TypeFlags.NumberLike */ | 12288 /* TypeFlags.ESSymbolLike */)) {
62127 if (objectType.flags & (1 /* TypeFlags.Any */ | 131072 /* TypeFlags.Never */)) {
62128 return objectType;
62129 }
62130 // If no index signature is applicable, we default to the string index signature. In effect, this means the string
62131 // index signature applies even when accessing with a symbol-like type.
62132 var indexInfo = getApplicableIndexInfo(objectType, indexType) || getIndexInfoOfType(objectType, stringType);
62133 if (indexInfo) {
62134 if (accessFlags & 2 /* AccessFlags.NoIndexSignatures */ && indexInfo.keyType !== numberType) {

Callers 1

Calls 15

getPropertyNameFromIndexFunction · 0.85
getPropertyOfTypeFunction · 0.85
isDeprecatedSymbolFunction · 0.85
addDeprecatedSuggestionFunction · 0.85
markPropertyAsReferencedFunction · 0.85
isSelfTypeAccessFunction · 0.85
symbolToStringFunction · 0.85
getNodeLinksFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…