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

Function instantiateMappedType

test/fixtures/snapshot/typescript.js:63499–63537  ·  view source on GitHub ↗
(type, mapper, aliasSymbol, aliasTypeArguments)

Source from the content-addressed store, hash-verified

63497 return undefined;
63498 }
63499 function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
63500 // For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
63501 // operation depends on T as follows:
63502 // * If T is a primitive type no mapping is performed and the result is simply T.
63503 // * If T is a union type we distribute the mapped type over the union.
63504 // * If T is an array we map to an array where the element type has been transformed.
63505 // * If T is a tuple we map to a tuple where the element types have been transformed.
63506 // * Otherwise we map to an object type where the type of each property has been transformed.
63507 // For example, when T is instantiated to a union type A | B, we produce { [P in keyof A]: X } |
63508 // { [P in keyof B]: X }, and when when T is instantiated to a union type A | undefined, we produce
63509 // { [P in keyof A]: X } | undefined.
63510 var typeVariable = getHomomorphicTypeVariable(type);
63511 if (typeVariable) {
63512 var mappedTypeVariable = instantiateType(typeVariable, mapper);
63513 if (typeVariable !== mappedTypeVariable) {
63514 return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
63515 if (t.flags & (3 /* TypeFlags.AnyOrUnknown */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */ | 524288 /* TypeFlags.Object */ | 2097152 /* TypeFlags.Intersection */) && t !== wildcardType && !isErrorType(t)) {
63516 if (!type.declaration.nameType) {
63517 var constraint = void 0;
63518 if (isArrayType(t) || t.flags & 1 /* TypeFlags.Any */ && findResolutionCycleStartIndex(typeVariable, 4 /* TypeSystemPropertyName.ImmediateBaseConstraint */) < 0 &&
63519 (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, isArrayOrTupleType)) {
63520 return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
63521 }
63522 if (isGenericTupleType(t)) {
63523 return instantiateMappedGenericTupleType(t, type, typeVariable, mapper);
63524 }
63525 if (isTupleType(t)) {
63526 return instantiateMappedTupleType(t, type, prependTypeMapping(typeVariable, t, mapper));
63527 }
63528 }
63529 return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
63530 }
63531 return t;
63532 }, aliasSymbol, aliasTypeArguments);
63533 }
63534 }
63535 // If the constraint type of the instantiation is the wildcard type, return the wildcard type.
63536 return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
63537 }
63538 function getModifiedReadonlyState(state, modifiers) {
63539 return modifiers & 1 /* MappedTypeModifiers.IncludeReadonly */ ? true : modifiers & 2 /* MappedTypeModifiers.ExcludeReadonly */ ? false : state;
63540 }

Callers 2

Calls 15

instantiateTypeFunction · 0.85
mapTypeWithAliasFunction · 0.85
getReducedTypeFunction · 0.85
isErrorTypeFunction · 0.85
isArrayTypeFunction · 0.85
everyTypeFunction · 0.85
prependTypeMappingFunction · 0.85
isGenericTupleTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…