@@ -14902,40 +14902,35 @@ namespace ts {
1490214902 return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType);
1490314903 }
1490414904
14905+ function isGenericType(type: Type): boolean {
14906+ return !!getGenericObjectFlags(type);
14907+ }
14908+
1490514909 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);
1492114911 }
1492214912
1492314913 function isGenericIndexType(type: Type): boolean {
14914+ return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericIndexType);
14915+ }
14916+
14917+ function getGenericObjectFlags(type: Type): ObjectFlags {
1492414918 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);
1492814922 }
14929- return !!(( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14923+ return ( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericType ;
1493014924 }
1493114925 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);
1493514929 }
14936- return !!(( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14930+ return ( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericType ;
1493714931 }
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);
1493914934 }
1494014935
1494114936 function isThisTypeParameter(type: Type): boolean {
@@ -15212,7 +15207,7 @@ namespace ts {
1521215207 while (true) {
1521315208 const isUnwrapped = isTypicalNondistributiveConditional(root);
1521415209 const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper);
15215- const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType (checkType);
15210+ const checkTypeInstantiable = isGenericType (checkType);
1521615211 const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
1521715212 if (checkType === wildcardType || extendsType === wildcardType) {
1521815213 return wildcardType;
@@ -15234,7 +15229,7 @@ namespace ts {
1523415229 // Instantiate the extends type including inferences for 'infer T' type parameters
1523515230 const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType;
1523615231 // 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)) {
1523815233 // Return falseType for a definitely false extends check. We check an instantiations of the two
1523915234 // types with type parameters mapped to the wildcard type, the most permissive instantiations
1524015235 // possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -24269,17 +24264,13 @@ namespace ts {
2426924264 return !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable));
2427024265 }
2427124266
24272- function containsGenericType(type: Type): boolean {
24273- return !!(type.flags & TypeFlags.Instantiable || type.flags & TypeFlags.UnionOrIntersection && some((type as UnionOrIntersectionType).types, containsGenericType));
24274- }
24275-
2427624267 function hasNonBindingPatternContextualTypeWithNoGenericTypes(node: Node) {
2427724268 // Computing the contextual type for a child of a JSX element involves resolving the type of the
2427824269 // element's tag name, so we exclude that here to avoid circularities.
2427924270 const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) &&
2428024271 !((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
2428124272 getContextualType(node, ContextFlags.SkipBindingPatterns);
24282- return contextualType && !someType (contextualType, containsGenericType );
24273+ return contextualType && !isGenericType (contextualType);
2428324274 }
2428424275
2428524276 function getNarrowableTypeForReference(type: Type, reference: Node, checkMode?: CheckMode) {
@@ -41659,7 +41650,7 @@ namespace ts {
4165941650 return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
4166041651 }
4166141652 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)) {
4166341654 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);
4166441655 }
4166541656 if (!everyType(type, isValidIndexKeyType)) {
0 commit comments