@@ -14857,40 +14857,35 @@ namespace ts {
14857
14857
return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType);
14858
14858
}
14859
14859
14860
+ function isGenericType(type: Type): boolean {
14861
+ return !!getGenericObjectFlags(type);
14862
+ }
14863
+
14860
14864
function isGenericObjectType(type: Type): boolean {
14861
- if (type.flags & TypeFlags.UnionOrIntersection) {
14862
- if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14863
- (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14864
- (some((type as UnionOrIntersectionType).types, isGenericObjectType) ? ObjectFlags.IsGenericObjectType : 0);
14865
- }
14866
- return !!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectType);
14867
- }
14868
- if (type.flags & TypeFlags.Substitution) {
14869
- if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14870
- (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14871
- (isGenericObjectType((type as SubstitutionType).substitute) || isGenericObjectType((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericObjectType : 0);
14872
- }
14873
- return !!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectType);
14874
- }
14875
- return !!(type.flags & TypeFlags.InstantiableNonPrimitive) || isGenericMappedType(type) || isGenericTupleType(type);
14865
+ return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericObjectType);
14876
14866
}
14877
14867
14878
14868
function isGenericIndexType(type: Type): boolean {
14869
+ return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericIndexType);
14870
+ }
14871
+
14872
+ function getGenericObjectFlags(type: Type): ObjectFlags {
14879
14873
if (type.flags & TypeFlags.UnionOrIntersection) {
14880
- if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed )) {
14881
- (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14882
- (some(( type as UnionOrIntersectionType).types, isGenericIndexType) ? ObjectFlags.IsGenericIndexType : 0);
14874
+ if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericTypeComputed )) {
14875
+ (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14876
+ reduceLeft(( type as UnionOrIntersectionType).types, (flags, t) => flags | getGenericObjectFlags(t), 0);
14883
14877
}
14884
- return !!(( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14878
+ return ( type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericType ;
14885
14879
}
14886
14880
if (type.flags & TypeFlags.Substitution) {
14887
- if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed )) {
14888
- (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14889
- (isGenericIndexType(( type as SubstitutionType).substitute) || isGenericIndexType ((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericIndexType : 0 );
14881
+ if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericTypeComputed )) {
14882
+ (type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14883
+ getGenericObjectFlags(( type as SubstitutionType).substitute) | getGenericObjectFlags ((type as SubstitutionType).baseType);
14890
14884
}
14891
- return !!(( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexType) ;
14885
+ return ( type as SubstitutionType).objectFlags & ObjectFlags.IsGenericType ;
14892
14886
}
14893
- return !!(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping)) && !isPatternLiteralType(type);
14887
+ return (type.flags & TypeFlags.InstantiableNonPrimitive || isGenericMappedType(type) || isGenericTupleType(type) ? ObjectFlags.IsGenericObjectType : 0) |
14888
+ (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0);
14894
14889
}
14895
14890
14896
14891
function isThisTypeParameter(type: Type): boolean {
@@ -15167,7 +15162,7 @@ namespace ts {
15167
15162
while (true) {
15168
15163
const isUnwrapped = isTypicalNondistributiveConditional(root);
15169
15164
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper);
15170
- const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType (checkType);
15165
+ const checkTypeInstantiable = isGenericType (checkType);
15171
15166
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
15172
15167
if (checkType === wildcardType || extendsType === wildcardType) {
15173
15168
return wildcardType;
@@ -15189,7 +15184,7 @@ namespace ts {
15189
15184
// Instantiate the extends type including inferences for 'infer T' type parameters
15190
15185
const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType;
15191
15186
// We attempt to resolve the conditional type only when the check and extends types are non-generic
15192
- if (!checkTypeInstantiable && !isGenericObjectType(inferredExtendsType) && !isGenericIndexType (inferredExtendsType)) {
15187
+ if (!checkTypeInstantiable && !isGenericType (inferredExtendsType)) {
15193
15188
// Return falseType for a definitely false extends check. We check an instantiations of the two
15194
15189
// types with type parameters mapped to the wildcard type, the most permissive instantiations
15195
15190
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -24248,7 +24243,7 @@ namespace ts {
24248
24243
const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) &&
24249
24244
!((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
24250
24245
getContextualType(node, ContextFlags.SkipBindingPatterns);
24251
- return contextualType && !(isGenericObjectType( contextualType) || isGenericIndexType(contextualType) );
24246
+ return contextualType && !isGenericType( contextualType);
24252
24247
}
24253
24248
24254
24249
function getNarrowableTypeForReference(type: Type, reference: Node, checkMode?: CheckMode) {
@@ -41578,7 +41573,7 @@ namespace ts {
41578
41573
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
41579
41574
}
41580
41575
const type = getTypeFromTypeNode(parameter.type);
41581
- if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericIndexType(type) || isGenericObjectType (type)) {
41576
+ if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericType (type)) {
41582
41577
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);
41583
41578
}
41584
41579
if (!everyType(type, isValidIndexKeyType)) {
0 commit comments