@@ -14902,40 +14902,35 @@ namespace ts {
14902
14902
return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType);
14903
14903
}
14904
14904
14905
+ function isGenericType(type: Type): boolean {
14906
+ return !!getGenericObjectFlags(type);
14907
+ }
14908
+
14905
14909
function isGenericObjectType(type: Type): boolean {
14906
- if (type.flags & TypeFlags.UnionOrIntersection) {
14907
- if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14908
- (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14909
- (some((type as UnionOrIntersectionType).types, isGenericObjectType) ? ObjectFlags.IsGenericObjectType : 0);
14910
- }
14911
- return !!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectType);
14912
- }
14913
- if (type.flags & TypeFlags.Substitution) {
14914
- if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14915
- (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14916
- (isGenericObjectType((type as SubstitutionType).substitute) || isGenericObjectType((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericObjectType : 0);
14917
- }
14918
- return !!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectType);
14919
- }
14920
- return !!(type.flags & TypeFlags.InstantiableNonPrimitive) || isGenericMappedType(type) || isGenericTupleType(type);
14910
+ return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericObjectType);
14921
14911
}
14922
14912
14923
14913
function isGenericIndexType(type: Type): boolean {
14914
+ return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericIndexType);
14915
+ }
14916
+
14917
+ function getGenericObjectFlags(type: Type): ObjectFlags {
14924
14918
if (type.flags & TypeFlags.UnionOrIntersection) {
14925
- if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed )) {
14926
- (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14927
- (some(( type as UnionOrIntersectionType).types, isGenericIndexType) ? ObjectFlags.IsGenericIndexType : 0);
14919
+ if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericTypeComputed )) {
14920
+ (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14921
+ reduceLeft(( type as UnionOrIntersectionType).types, (flags, t) => flags | getGenericObjectFlags(t), 0);
14928
14922
}
14929
- return !!(( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14923
+ return ( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericType ;
14930
14924
}
14931
14925
if (type.flags & TypeFlags.Substitution) {
14932
- if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed )) {
14933
- (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14934
- (isGenericIndexType(( type as SubstitutionType).substitute) || isGenericIndexType ((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericIndexType : 0 );
14926
+ if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericTypeComputed )) {
14927
+ (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14928
+ getGenericObjectFlags(( type as SubstitutionType).substitute) | getGenericObjectFlags ((type as SubstitutionType).baseType);
14935
14929
}
14936
- return !!(( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14930
+ return ( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericType ;
14937
14931
}
14938
- return !!(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping)) && !isPatternLiteralType(type);
14932
+ return (type.flags & TypeFlags.InstantiableNonPrimitive || isGenericMappedType(type) || isGenericTupleType(type) ? ObjectFlags.IsGenericObjectType : 0) |
14933
+ (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0);
14939
14934
}
14940
14935
14941
14936
function isThisTypeParameter(type: Type): boolean {
@@ -15212,7 +15207,7 @@ namespace ts {
15212
15207
while (true) {
15213
15208
const isUnwrapped = isTypicalNondistributiveConditional(root);
15214
15209
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper);
15215
- const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType (checkType);
15210
+ const checkTypeInstantiable = isGenericType (checkType);
15216
15211
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
15217
15212
if (checkType === wildcardType || extendsType === wildcardType) {
15218
15213
return wildcardType;
@@ -15234,7 +15229,7 @@ namespace ts {
15234
15229
// Instantiate the extends type including inferences for 'infer T' type parameters
15235
15230
const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType;
15236
15231
// We attempt to resolve the conditional type only when the check and extends types are non-generic
15237
- if (!checkTypeInstantiable && !isGenericObjectType(inferredExtendsType) && !isGenericIndexType (inferredExtendsType)) {
15232
+ if (!checkTypeInstantiable && !isGenericType (inferredExtendsType)) {
15238
15233
// Return falseType for a definitely false extends check. We check an instantiations of the two
15239
15234
// types with type parameters mapped to the wildcard type, the most permissive instantiations
15240
15235
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -24269,17 +24264,13 @@ namespace ts {
24269
24264
return !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable));
24270
24265
}
24271
24266
24272
- function containsGenericType(type: Type): boolean {
24273
- return !!(type.flags & TypeFlags.Instantiable || type.flags & TypeFlags.UnionOrIntersection && some((type as UnionOrIntersectionType).types, containsGenericType));
24274
- }
24275
-
24276
24267
function hasNonBindingPatternContextualTypeWithNoGenericTypes(node: Node) {
24277
24268
// Computing the contextual type for a child of a JSX element involves resolving the type of the
24278
24269
// element's tag name, so we exclude that here to avoid circularities.
24279
24270
const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) &&
24280
24271
!((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
24281
24272
getContextualType(node, ContextFlags.SkipBindingPatterns);
24282
- return contextualType && !someType (contextualType, containsGenericType );
24273
+ return contextualType && !isGenericType (contextualType);
24283
24274
}
24284
24275
24285
24276
function getNarrowableTypeForReference(type: Type, reference: Node, checkMode?: CheckMode) {
@@ -41659,7 +41650,7 @@ namespace ts {
41659
41650
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
41660
41651
}
41661
41652
const type = getTypeFromTypeNode(parameter.type);
41662
- if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericIndexType(type) || isGenericObjectType (type)) {
41653
+ if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericType (type)) {
41663
41654
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead);
41664
41655
}
41665
41656
if (!everyType(type, isValidIndexKeyType)) {
0 commit comments