Update LKG

This commit is contained in:
TypeScript Bot
2021-01-12 02:22:05 +00:00
parent 7484c40ee5
commit fd95fe94fb
6 changed files with 540 additions and 292 deletions
+75 -47
View File
@@ -5304,7 +5304,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -45152,15 +45152,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -45218,17 +45221,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -45244,7 +45247,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -47009,7 +47013,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
while (true) {
@@ -47055,8 +47059,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper);
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -47723,7 +47727,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 ? links.resolvedType :
@@ -47744,17 +47748,19 @@ var ts;
if (typeParameters.length) {
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -47800,12 +47806,12 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
var typeVariable = getHomomorphicTypeVariable(type);
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 | 58982400 | 524288 | 2097152) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -47821,10 +47827,10 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 ? true : modifiers & 2 ? false : state;
@@ -47866,7 +47872,7 @@ var ts;
strictNullChecks && modifiers & 8 && isOptional ? getTypeWithFacts(propType, 524288) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64, type.symbol);
if (type.objectFlags & 32) {
result.declaration = type.declaration;
@@ -47878,37 +47884,40 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
if (root.isDistributive) {
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 | 131072)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, undefined, undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -47919,11 +47928,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144) {
return getMappedType(type, mapper);
@@ -47931,12 +47940,12 @@ var ts;
if (flags & 524288) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 | 16 | 32)) {
if (objectFlags & 4 && !(type.node)) {
if (objectFlags & 4 && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -47944,10 +47953,14 @@ var ts;
var origin = type.flags & 1048576 ? type.origin : undefined;
var types = origin && origin.flags & 3145728 ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 || origin && origin.flags & 2097152 ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 || origin && origin.flags & 2097152 ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304) {
return getIndexType(instantiateType(type.type, mapper));
@@ -47959,10 +47972,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -52882,6 +52897,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 : 1) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 ? type.types.length : 1;
}
@@ -53011,10 +53031,15 @@ var ts;
return getExplicitThisType(node);
case 105:
return checkSuperExpression(node);
case 201:
case 201: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -59551,8 +59576,11 @@ var ts;
isTypeAssignableToKind(leftType, 4194304 | 134217728 | 268435456 | 262144))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 | 58982400)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 | 58982400) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 | 58982400) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 | 58982400 | 524288))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}
+93 -49
View File
@@ -7979,7 +7979,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -54686,15 +54686,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4 /* Reference */, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -54759,17 +54762,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -54790,7 +54793,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -55892,7 +55896,7 @@ var ts;
var result = createType(2097152 /* Intersection */);
result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ 98304 /* Nullable */);
result.types = types;
result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
result.aliasSymbol = aliasSymbol;
result.aliasTypeArguments = aliasTypeArguments;
return result;
}
@@ -56734,7 +56738,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
// We loop here for an immediately nested conditional type in the false position, effectively treating
@@ -56801,8 +56805,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -57518,7 +57522,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
@@ -57546,17 +57550,19 @@ var ts;
// instantiation cache key from the type IDs of the type arguments.
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -57605,7 +57611,7 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
// For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
// operation depends on T as follows:
// * If T is a primitive type no mapping is performed and the result is simply T.
@@ -57620,7 +57626,7 @@ var ts;
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -57636,11 +57642,11 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 /* IncludeReadonly */ ? true : modifiers & 2 /* ExcludeReadonly */ ? false : state;
@@ -57687,7 +57693,7 @@ var ts;
strictNullChecks && modifiers & 8 /* ExcludeOptional */ && isOptional ? getTypeWithFacts(propType, 524288 /* NEUndefined */) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64 /* Instantiated */, type.symbol);
if (type.objectFlags & 32 /* Mapped */) {
result.declaration = type.declaration;
@@ -57700,29 +57706,29 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
// We are instantiating a conditional type that has one or more type parameters in scope. Apply the
// mapper to the type parameters to produce the effective list of type arguments, and compute the
// instantiation cache key from the type IDs of the type arguments.
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
// Check if we have a conditional type where the check type is a naked type parameter. If so,
// the conditional type is distributive over union types and when T is instantiated to a union
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
@@ -57730,13 +57736,16 @@ var ts;
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -57750,11 +57759,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144 /* TypeParameter */) {
return getMappedType(type, mapper);
@@ -57762,12 +57771,12 @@ var ts;
if (flags & 524288 /* Object */) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 /* Reference */ | 16 /* Anonymous */ | 32 /* Mapped */)) {
if (objectFlags & 4 /* Reference */ && !(type.node)) {
if (objectFlags & 4 /* Reference */ && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -57775,10 +57784,14 @@ var ts;
var origin = type.flags & 1048576 /* Union */ ? type.origin : undefined;
var types = origin && origin.flags & 3145728 /* UnionOrIntersection */ ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1 /* Literal */, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1 /* Literal */, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304 /* Index */) {
return getIndexType(instantiateType(type.type, mapper));
@@ -57790,10 +57803,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608 /* IndexedAccess */) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216 /* Conditional */) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432 /* Substitution */) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -63436,6 +63451,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 /* Union */ && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 /* UnionOrIntersection */ ? type.types.length : 1;
}
@@ -63582,10 +63602,15 @@ var ts;
return getExplicitThisType(node);
case 105 /* SuperKeyword */:
return checkSuperExpression(node);
case 201 /* PropertyAccessExpression */:
case 201 /* PropertyAccessExpression */: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207 /* ParenthesizedExpression */:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -71250,14 +71275,33 @@ var ts;
rightType = checkNonNullType(rightType, right);
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// and the right operand to be
//
// 1. assignable to the non-primitive type,
// 2. an unconstrained type parameter,
// 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
// the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
// non-primitive type, or
// 4. a type parameter whose constraint is
// i. an object type,
// ii. the non-primitive type, or
// iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
//
// The divergent behavior for type parameters and unions containing type parameters is a workaround for type
// parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
// it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
// unless *all* instantiations would result in an error.
//
// The result is always of the Boolean primitive type.
if (!(allTypesAssignableToKind(leftType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */) ||
isTypeAssignableToKind(leftType, 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 262144 /* TypeParameter */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}
+93 -49
View File
@@ -8173,7 +8173,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -54880,15 +54880,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4 /* Reference */, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -54953,17 +54956,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -54984,7 +54987,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -56086,7 +56090,7 @@ var ts;
var result = createType(2097152 /* Intersection */);
result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ 98304 /* Nullable */);
result.types = types;
result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
result.aliasSymbol = aliasSymbol;
result.aliasTypeArguments = aliasTypeArguments;
return result;
}
@@ -56928,7 +56932,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
// We loop here for an immediately nested conditional type in the false position, effectively treating
@@ -56995,8 +56999,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -57712,7 +57716,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
@@ -57740,17 +57744,19 @@ var ts;
// instantiation cache key from the type IDs of the type arguments.
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -57799,7 +57805,7 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
// For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
// operation depends on T as follows:
// * If T is a primitive type no mapping is performed and the result is simply T.
@@ -57814,7 +57820,7 @@ var ts;
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -57830,11 +57836,11 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 /* IncludeReadonly */ ? true : modifiers & 2 /* ExcludeReadonly */ ? false : state;
@@ -57881,7 +57887,7 @@ var ts;
strictNullChecks && modifiers & 8 /* ExcludeOptional */ && isOptional ? getTypeWithFacts(propType, 524288 /* NEUndefined */) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64 /* Instantiated */, type.symbol);
if (type.objectFlags & 32 /* Mapped */) {
result.declaration = type.declaration;
@@ -57894,29 +57900,29 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
// We are instantiating a conditional type that has one or more type parameters in scope. Apply the
// mapper to the type parameters to produce the effective list of type arguments, and compute the
// instantiation cache key from the type IDs of the type arguments.
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
// Check if we have a conditional type where the check type is a naked type parameter. If so,
// the conditional type is distributive over union types and when T is instantiated to a union
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
@@ -57924,13 +57930,16 @@ var ts;
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -57944,11 +57953,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144 /* TypeParameter */) {
return getMappedType(type, mapper);
@@ -57956,12 +57965,12 @@ var ts;
if (flags & 524288 /* Object */) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 /* Reference */ | 16 /* Anonymous */ | 32 /* Mapped */)) {
if (objectFlags & 4 /* Reference */ && !(type.node)) {
if (objectFlags & 4 /* Reference */ && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -57969,10 +57978,14 @@ var ts;
var origin = type.flags & 1048576 /* Union */ ? type.origin : undefined;
var types = origin && origin.flags & 3145728 /* UnionOrIntersection */ ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1 /* Literal */, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1 /* Literal */, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304 /* Index */) {
return getIndexType(instantiateType(type.type, mapper));
@@ -57984,10 +57997,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608 /* IndexedAccess */) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216 /* Conditional */) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432 /* Substitution */) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -63630,6 +63645,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 /* Union */ && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 /* UnionOrIntersection */ ? type.types.length : 1;
}
@@ -63776,10 +63796,15 @@ var ts;
return getExplicitThisType(node);
case 105 /* SuperKeyword */:
return checkSuperExpression(node);
case 201 /* PropertyAccessExpression */:
case 201 /* PropertyAccessExpression */: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207 /* ParenthesizedExpression */:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -71444,14 +71469,33 @@ var ts;
rightType = checkNonNullType(rightType, right);
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// and the right operand to be
//
// 1. assignable to the non-primitive type,
// 2. an unconstrained type parameter,
// 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
// the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
// non-primitive type, or
// 4. a type parameter whose constraint is
// i. an object type,
// ii. the non-primitive type, or
// iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
//
// The divergent behavior for type parameters and unions containing type parameters is a workaround for type
// parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
// it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
// unless *all* instantiations would result in an error.
//
// The result is always of the Boolean primitive type.
if (!(allTypesAssignableToKind(leftType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */) ||
isTypeAssignableToKind(leftType, 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 262144 /* TypeParameter */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}
+93 -49
View File
@@ -8173,7 +8173,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -54880,15 +54880,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4 /* Reference */, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -54953,17 +54956,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -54984,7 +54987,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -56086,7 +56090,7 @@ var ts;
var result = createType(2097152 /* Intersection */);
result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ 98304 /* Nullable */);
result.types = types;
result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
result.aliasSymbol = aliasSymbol;
result.aliasTypeArguments = aliasTypeArguments;
return result;
}
@@ -56928,7 +56932,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
// We loop here for an immediately nested conditional type in the false position, effectively treating
@@ -56995,8 +56999,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -57712,7 +57716,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
@@ -57740,17 +57744,19 @@ var ts;
// instantiation cache key from the type IDs of the type arguments.
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -57799,7 +57805,7 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
// For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
// operation depends on T as follows:
// * If T is a primitive type no mapping is performed and the result is simply T.
@@ -57814,7 +57820,7 @@ var ts;
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -57830,11 +57836,11 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 /* IncludeReadonly */ ? true : modifiers & 2 /* ExcludeReadonly */ ? false : state;
@@ -57881,7 +57887,7 @@ var ts;
strictNullChecks && modifiers & 8 /* ExcludeOptional */ && isOptional ? getTypeWithFacts(propType, 524288 /* NEUndefined */) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64 /* Instantiated */, type.symbol);
if (type.objectFlags & 32 /* Mapped */) {
result.declaration = type.declaration;
@@ -57894,29 +57900,29 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
// We are instantiating a conditional type that has one or more type parameters in scope. Apply the
// mapper to the type parameters to produce the effective list of type arguments, and compute the
// instantiation cache key from the type IDs of the type arguments.
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
// Check if we have a conditional type where the check type is a naked type parameter. If so,
// the conditional type is distributive over union types and when T is instantiated to a union
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
@@ -57924,13 +57930,16 @@ var ts;
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -57944,11 +57953,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144 /* TypeParameter */) {
return getMappedType(type, mapper);
@@ -57956,12 +57965,12 @@ var ts;
if (flags & 524288 /* Object */) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 /* Reference */ | 16 /* Anonymous */ | 32 /* Mapped */)) {
if (objectFlags & 4 /* Reference */ && !(type.node)) {
if (objectFlags & 4 /* Reference */ && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -57969,10 +57978,14 @@ var ts;
var origin = type.flags & 1048576 /* Union */ ? type.origin : undefined;
var types = origin && origin.flags & 3145728 /* UnionOrIntersection */ ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1 /* Literal */, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1 /* Literal */, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304 /* Index */) {
return getIndexType(instantiateType(type.type, mapper));
@@ -57984,10 +57997,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608 /* IndexedAccess */) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216 /* Conditional */) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432 /* Substitution */) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -63630,6 +63645,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 /* Union */ && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 /* UnionOrIntersection */ ? type.types.length : 1;
}
@@ -63776,10 +63796,15 @@ var ts;
return getExplicitThisType(node);
case 105 /* SuperKeyword */:
return checkSuperExpression(node);
case 201 /* PropertyAccessExpression */:
case 201 /* PropertyAccessExpression */: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207 /* ParenthesizedExpression */:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -71444,14 +71469,33 @@ var ts;
rightType = checkNonNullType(rightType, right);
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// and the right operand to be
//
// 1. assignable to the non-primitive type,
// 2. an unconstrained type parameter,
// 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
// the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
// non-primitive type, or
// 4. a type parameter whose constraint is
// i. an object type,
// ii. the non-primitive type, or
// iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
//
// The divergent behavior for type parameters and unions containing type parameters is a workaround for type
// parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
// it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
// unless *all* instantiations would result in an error.
//
// The result is always of the Boolean primitive type.
if (!(allTypesAssignableToKind(leftType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */) ||
isTypeAssignableToKind(leftType, 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 262144 /* TypeParameter */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}
+93 -49
View File
@@ -8173,7 +8173,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -54880,15 +54880,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4 /* Reference */, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -54953,17 +54956,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -54984,7 +54987,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -56086,7 +56090,7 @@ var ts;
var result = createType(2097152 /* Intersection */);
result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ 98304 /* Nullable */);
result.types = types;
result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
result.aliasSymbol = aliasSymbol;
result.aliasTypeArguments = aliasTypeArguments;
return result;
}
@@ -56928,7 +56932,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
// We loop here for an immediately nested conditional type in the false position, effectively treating
@@ -56995,8 +56999,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -57712,7 +57716,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
@@ -57740,17 +57744,19 @@ var ts;
// instantiation cache key from the type IDs of the type arguments.
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -57799,7 +57805,7 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
// For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
// operation depends on T as follows:
// * If T is a primitive type no mapping is performed and the result is simply T.
@@ -57814,7 +57820,7 @@ var ts;
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -57830,11 +57836,11 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 /* IncludeReadonly */ ? true : modifiers & 2 /* ExcludeReadonly */ ? false : state;
@@ -57881,7 +57887,7 @@ var ts;
strictNullChecks && modifiers & 8 /* ExcludeOptional */ && isOptional ? getTypeWithFacts(propType, 524288 /* NEUndefined */) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64 /* Instantiated */, type.symbol);
if (type.objectFlags & 32 /* Mapped */) {
result.declaration = type.declaration;
@@ -57894,29 +57900,29 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
// We are instantiating a conditional type that has one or more type parameters in scope. Apply the
// mapper to the type parameters to produce the effective list of type arguments, and compute the
// instantiation cache key from the type IDs of the type arguments.
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
// Check if we have a conditional type where the check type is a naked type parameter. If so,
// the conditional type is distributive over union types and when T is instantiated to a union
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
@@ -57924,13 +57930,16 @@ var ts;
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -57944,11 +57953,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144 /* TypeParameter */) {
return getMappedType(type, mapper);
@@ -57956,12 +57965,12 @@ var ts;
if (flags & 524288 /* Object */) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 /* Reference */ | 16 /* Anonymous */ | 32 /* Mapped */)) {
if (objectFlags & 4 /* Reference */ && !(type.node)) {
if (objectFlags & 4 /* Reference */ && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -57969,10 +57978,14 @@ var ts;
var origin = type.flags & 1048576 /* Union */ ? type.origin : undefined;
var types = origin && origin.flags & 3145728 /* UnionOrIntersection */ ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1 /* Literal */, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1 /* Literal */, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304 /* Index */) {
return getIndexType(instantiateType(type.type, mapper));
@@ -57984,10 +57997,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608 /* IndexedAccess */) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216 /* Conditional */) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432 /* Substitution */) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -63630,6 +63645,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 /* Union */ && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 /* UnionOrIntersection */ ? type.types.length : 1;
}
@@ -63776,10 +63796,15 @@ var ts;
return getExplicitThisType(node);
case 105 /* SuperKeyword */:
return checkSuperExpression(node);
case 201 /* PropertyAccessExpression */:
case 201 /* PropertyAccessExpression */: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207 /* ParenthesizedExpression */:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -71444,14 +71469,33 @@ var ts;
rightType = checkNonNullType(rightType, right);
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// and the right operand to be
//
// 1. assignable to the non-primitive type,
// 2. an unconstrained type parameter,
// 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
// the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
// non-primitive type, or
// 4. a type parameter whose constraint is
// i. an object type,
// ii. the non-primitive type, or
// iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
//
// The divergent behavior for type parameters and unions containing type parameters is a workaround for type
// parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
// it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
// unless *all* instantiations would result in an error.
//
// The result is always of the Boolean primitive type.
if (!(allTypesAssignableToKind(leftType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */) ||
isTypeAssignableToKind(leftType, 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 262144 /* TypeParameter */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}
+93 -49
View File
@@ -7968,7 +7968,7 @@ var ts;
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: diag(2360, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol_2360", "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'."),
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter_2361", "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter."),
The_right_hand_side_of_an_in_expression_must_not_be_a_primitive: diag(2361, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361", "The right-hand side of an 'in' expression must not be a primitive."),
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, ts.DiagnosticCategory.Error, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -54675,15 +54675,18 @@ var ts;
type.resolvedTypeArguments = source.resolvedTypeArguments;
return type;
}
function createDeferredTypeReference(target, node, mapper) {
var aliasSymbol = getAliasSymbolForTypeNode(node);
var aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target, node, mapper, aliasSymbol, aliasTypeArguments) {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
var localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
var type = createObjectType(4 /* Reference */, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}
function getTypeArguments(type) {
@@ -54748,17 +54751,17 @@ var ts;
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
function getTypeAliasInstantiation(symbol, typeArguments) {
function getTypeAliasInstantiation(symbol, typeArguments, aliasSymbol, aliasTypeArguments) {
var type = getDeclaredTypeOfSymbol(symbol);
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName) && typeArguments && typeArguments.length === 1) {
return getStringMappingType(symbol, typeArguments[0]);
}
var links = getSymbolLinks(symbol);
var typeParameters = links.typeParameters;
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var instantiation = links.instantiations.get(id);
if (!instantiation) {
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration)))));
links.instantiations.set(id, instantiation = instantiateTypeWithAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), ts.isInJSFile(symbol.valueDeclaration))), aliasSymbol, aliasTypeArguments));
}
return instantiation;
}
@@ -54779,7 +54782,8 @@ var ts;
ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length);
return errorType;
}
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
var aliasSymbol = getAliasSymbolForTypeNode(node);
return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
}
return checkNoTypeArguments(node, symbol) ? type : errorType;
}
@@ -55881,7 +55885,7 @@ var ts;
var result = createType(2097152 /* Intersection */);
result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ 98304 /* Nullable */);
result.types = types;
result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
result.aliasSymbol = aliasSymbol;
result.aliasTypeArguments = aliasTypeArguments;
return result;
}
@@ -56723,7 +56727,7 @@ var ts;
}
return type;
}
function getConditionalType(root, mapper) {
function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
var result;
var extraTypes;
// We loop here for an immediately nested conditional type in the false position, effectively treating
@@ -56790,8 +56794,8 @@ var ts;
result.extendsType = extendsType;
result.mapper = mapper;
result.combinedMapper = combinedMapper;
result.aliasSymbol = root.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
result.aliasSymbol = aliasSymbol || root.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(root.aliasTypeArguments, mapper); // TODO: GH#18217
break;
}
return extraTypes ? getUnionType(ts.append(extraTypes, result)) : result;
@@ -57507,7 +57511,7 @@ var ts;
}
return result;
}
function getObjectTypeInstantiation(type, mapper) {
function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
var links = getNodeLinks(declaration);
var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
@@ -57535,17 +57539,19 @@ var ts;
// instantiation cache key from the type IDs of the type arguments.
var combinedMapper_1 = combineTypeMappers(type.mapper, mapper);
var typeArguments = ts.map(typeParameters, function (t) { return getMappedType(t, combinedMapper_1); });
var id = getTypeListId(typeArguments);
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var id = getTypeListId(typeArguments) + (newAliasSymbol ? "@" + getSymbolId(newAliasSymbol) : "");
if (!target.instantiations) {
target.instantiations = new ts.Map();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? "@" + getSymbolId(target.aliasSymbol) : ""), target);
}
var result = target.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper) :
instantiateAnonymousType(target, newMapper);
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
@@ -57594,7 +57600,7 @@ var ts;
}
return undefined;
}
function instantiateMappedType(type, mapper) {
function instantiateMappedType(type, mapper, aliasSymbol, aliasTypeArguments) {
// For a homomorphic mapped type { [P in keyof T]: X }, where T is some type variable, the mapping
// operation depends on T as follows:
// * If T is a primitive type no mapping is performed and the result is simply T.
@@ -57609,7 +57615,7 @@ var ts;
if (typeVariable) {
var mappedTypeVariable = instantiateType(typeVariable, mapper);
if (typeVariable !== mappedTypeVariable) {
return mapType(getReducedType(mappedTypeVariable), function (t) {
return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && t !== errorType) {
if (!type.declaration.nameType) {
if (isArrayType(t)) {
@@ -57625,11 +57631,11 @@ var ts;
return instantiateAnonymousType(type, prependTypeMapping(typeVariable, t, mapper));
}
return t;
});
}, aliasSymbol, aliasTypeArguments);
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments);
}
function getModifiedReadonlyState(state, modifiers) {
return modifiers & 1 /* IncludeReadonly */ ? true : modifiers & 2 /* ExcludeReadonly */ ? false : state;
@@ -57676,7 +57682,7 @@ var ts;
strictNullChecks && modifiers & 8 /* ExcludeOptional */ && isOptional ? getTypeWithFacts(propType, 524288 /* NEUndefined */) :
propType;
}
function instantiateAnonymousType(type, mapper) {
function instantiateAnonymousType(type, mapper, aliasSymbol, aliasTypeArguments) {
var result = createObjectType(type.objectFlags | 64 /* Instantiated */, type.symbol);
if (type.objectFlags & 32 /* Mapped */) {
result.declaration = type.declaration;
@@ -57689,29 +57695,29 @@ var ts;
}
result.target = type;
result.mapper = mapper;
result.aliasSymbol = type.aliasSymbol;
result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper);
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return result;
}
function getConditionalTypeInstantiation(type, mapper) {
function getConditionalTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
var root = type.root;
if (root.outerTypeParameters) {
// We are instantiating a conditional type that has one or more type parameters in scope. Apply the
// mapper to the type parameters to produce the effective list of type arguments, and compute the
// instantiation cache key from the type IDs of the type arguments.
var typeArguments = ts.map(root.outerTypeParameters, function (t) { return getMappedType(t, mapper); });
var id = getTypeListId(typeArguments);
var id = getTypeListId(typeArguments) + (aliasSymbol ? "@" + getSymbolId(aliasSymbol) : "");
var result = root.instantiations.get(id);
if (!result) {
var newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
result = instantiateConditionalType(root, newMapper);
result = instantiateConditionalType(root, newMapper, aliasSymbol, aliasTypeArguments);
root.instantiations.set(id, result);
}
return result;
}
return type;
}
function instantiateConditionalType(root, mapper) {
function instantiateConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) {
// Check if we have a conditional type where the check type is a naked type parameter. If so,
// the conditional type is distributive over union types and when T is instantiated to a union
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
@@ -57719,13 +57725,16 @@ var ts;
var checkType_1 = root.checkType;
var instantiatedType = getMappedType(checkType_1, mapper);
if (checkType_1 !== instantiatedType && instantiatedType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
return mapType(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); });
return mapTypeWithAlias(instantiatedType, function (t) { return getConditionalType(root, prependTypeMapping(checkType_1, t, mapper)); }, aliasSymbol, aliasTypeArguments);
}
}
return getConditionalType(root, mapper);
return getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments);
}
function instantiateType(type, mapper) {
if (!(type && mapper && couldContainTypeVariables(type))) {
return type && mapper ? instantiateTypeWithAlias(type, mapper, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined) : type;
}
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
if (!couldContainTypeVariables(type)) {
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -57739,11 +57748,11 @@ var ts;
totalInstantiationCount++;
instantiationCount++;
instantiationDepth++;
var result = instantiateTypeWorker(type, mapper);
var result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
instantiationDepth--;
return result;
}
function instantiateTypeWorker(type, mapper) {
function instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments) {
var flags = type.flags;
if (flags & 262144 /* TypeParameter */) {
return getMappedType(type, mapper);
@@ -57751,12 +57760,12 @@ var ts;
if (flags & 524288 /* Object */) {
var objectFlags = type.objectFlags;
if (objectFlags & (4 /* Reference */ | 16 /* Anonymous */ | 32 /* Mapped */)) {
if (objectFlags & 4 /* Reference */ && !(type.node)) {
if (objectFlags & 4 /* Reference */ && !type.node) {
var resolvedTypeArguments = type.resolvedTypeArguments;
var newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference(type.target, newTypeArguments) : type;
}
return getObjectTypeInstantiation(type, mapper);
return getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
}
@@ -57764,10 +57773,14 @@ var ts;
var origin = type.flags & 1048576 /* Union */ ? type.origin : undefined;
var types = origin && origin.flags & 3145728 /* UnionOrIntersection */ ? origin.types : type.types;
var newTypes = instantiateTypes(types, mapper);
return newTypes === types ? type :
flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
getUnionType(newTypes, 1 /* Literal */, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
if (newTypes === types && aliasSymbol === type.aliasSymbol) {
return type;
}
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return flags & 2097152 /* Intersection */ || origin && origin.flags & 2097152 /* Intersection */ ?
getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
getUnionType(newTypes, 1 /* Literal */, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 4194304 /* Index */) {
return getIndexType(instantiateType(type.type, mapper));
@@ -57779,10 +57792,12 @@ var ts;
return getStringMappingType(type.symbol, instantiateType(type.type, mapper));
}
if (flags & 8388608 /* IndexedAccess */) {
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
var newAliasSymbol = aliasSymbol || type.aliasSymbol;
var newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper), type.noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
}
if (flags & 16777216 /* Conditional */) {
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper));
return getConditionalTypeInstantiation(type, combineTypeMappers(type.mapper, mapper), aliasSymbol, aliasTypeArguments);
}
if (flags & 33554432 /* Substitution */) {
var maybeVariable = instantiateType(type.baseType, mapper);
@@ -63425,6 +63440,11 @@ var ts;
}
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
}
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
return type.flags & 1048576 /* Union */ && aliasSymbol ?
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
mapType(type, mapper);
}
function getConstituentCount(type) {
return type.flags & 3145728 /* UnionOrIntersection */ ? type.types.length : 1;
}
@@ -63571,10 +63591,15 @@ var ts;
return getExplicitThisType(node);
case 105 /* SuperKeyword */:
return checkSuperExpression(node);
case 201 /* PropertyAccessExpression */:
case 201 /* PropertyAccessExpression */: {
var type = getTypeOfDottedName(node.expression, diagnostic);
var prop = type && getPropertyOfType(type, node.name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
if (type) {
var name = node.name;
var prop = getPropertyOfType(type, ts.isPrivateIdentifier(name) ? ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
}
case 207 /* ParenthesizedExpression */:
return getTypeOfDottedName(node.expression, diagnostic);
}
@@ -71239,14 +71264,33 @@ var ts;
rightType = checkNonNullType(rightType, right);
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// and the right operand to be
//
// 1. assignable to the non-primitive type,
// 2. an unconstrained type parameter,
// 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
// the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
// non-primitive type, or
// 4. a type parameter whose constraint is
// i. an object type,
// ii. the non-primitive type, or
// iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
//
// The divergent behavior for type parameters and unions containing type parameters is a workaround for type
// parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
// it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
// unless *all* instantiations would result in an error.
//
// The result is always of the Boolean primitive type.
if (!(allTypesAssignableToKind(leftType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */) ||
isTypeAssignableToKind(leftType, 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 262144 /* TypeParameter */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
var rightTypeConstraint = getConstraintOfType(rightType);
if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */) ||
!maybeTypeOfKind(rightTypeConstraint, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */))) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
}
return booleanType;
}