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

Function addMemberForKeyTypeWorker

test/fixtures/snapshot/typescript.js:58563–58605  ·  view source on GitHub ↗
(keyType, propNameType)

Source from the content-addressed store, hash-verified

58561 forEachType(propNameType, function (t) { return addMemberForKeyTypeWorker(keyType, t); });
58562 }
58563 function addMemberForKeyTypeWorker(keyType, propNameType) {
58564 // If the current iteration type constituent is a string literal type, create a property.
58565 // Otherwise, for type string create a string index signature.
58566 if (isTypeUsableAsPropertyName(propNameType)) {
58567 var propName = getPropertyNameFromType(propNameType);
58568 // String enum members from separate enums with identical values
58569 // are distinct types with the same property name. Make the resulting
58570 // property symbol's name type be the union of those enum member types.
58571 var existingProp = members.get(propName);
58572 if (existingProp) {
58573 existingProp.nameType = getUnionType([existingProp.nameType, propNameType]);
58574 existingProp.keyType = getUnionType([existingProp.keyType, keyType]);
58575 }
58576 else {
58577 var modifiersProp = isTypeUsableAsPropertyName(keyType) ? getPropertyOfType(modifiersType, getPropertyNameFromType(keyType)) : undefined;
58578 var isOptional = !!(templateModifiers & 4 /* MappedTypeModifiers.IncludeOptional */ ||
58579 !(templateModifiers & 8 /* MappedTypeModifiers.ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* SymbolFlags.Optional */);
58580 var isReadonly = !!(templateModifiers & 1 /* MappedTypeModifiers.IncludeReadonly */ ||
58581 !(templateModifiers & 2 /* MappedTypeModifiers.ExcludeReadonly */) && modifiersProp && isReadonlySymbol(modifiersProp));
58582 var stripOptional = strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & 16777216 /* SymbolFlags.Optional */;
58583 var lateFlag = modifiersProp ? getIsLateCheckFlag(modifiersProp) : 0;
58584 var prop = createSymbol(4 /* SymbolFlags.Property */ | (isOptional ? 16777216 /* SymbolFlags.Optional */ : 0), propName, lateFlag | 262144 /* CheckFlags.Mapped */ | (isReadonly ? 8 /* CheckFlags.Readonly */ : 0) | (stripOptional ? 524288 /* CheckFlags.StripOptional */ : 0));
58585 prop.mappedType = type;
58586 prop.nameType = propNameType;
58587 prop.keyType = keyType;
58588 if (modifiersProp) {
58589 prop.syntheticOrigin = modifiersProp;
58590 // If the mapped type has an `as XXX` clause, the property name likely won't match the declaration name and
58591 // multiple properties may map to the same name. Thus, we attach no declarations to the symbol.
58592 prop.declarations = nameType ? undefined : modifiersProp.declarations;
58593 }
58594 members.set(propName, prop);
58595 }
58596 }
58597 else if (isValidIndexKeyType(propNameType) || propNameType.flags & (1 /* TypeFlags.Any */ | 32 /* TypeFlags.Enum */)) {
58598 var indexKeyType = propNameType.flags & (1 /* TypeFlags.Any */ | 4 /* TypeFlags.String */) ? stringType :
58599 propNameType.flags & (8 /* TypeFlags.Number */ | 32 /* TypeFlags.Enum */) ? numberType :
58600 propNameType;
58601 var propType = instantiateType(templateType, appendTypeMapping(type.mapper, typeParameter, keyType));
58602 var indexInfo = createIndexInfo(indexKeyType, propType, !!(templateModifiers & 1 /* MappedTypeModifiers.IncludeReadonly */));
58603 indexInfos = appendIndexInfo(indexInfos, indexInfo, /*union*/ true);
58604 }
58605 }
58606 }
58607 function getTypeOfMappedSymbol(symbol) {
58608 if (!symbol.type) {

Callers 1

addMemberForKeyTypeFunction · 0.85

Calls 14

getPropertyNameFromTypeFunction · 0.85
getUnionTypeFunction · 0.85
getPropertyOfTypeFunction · 0.85
isReadonlySymbolFunction · 0.85
getIsLateCheckFlagFunction · 0.85
createSymbolFunction · 0.85
isValidIndexKeyTypeFunction · 0.85
instantiateTypeFunction · 0.85
appendTypeMappingFunction · 0.85
createIndexInfoFunction · 0.85
appendIndexInfoFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…