mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add IndexFlags.FromIntersection
This commit is contained in:
@@ -18075,9 +18075,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function getIndexTypeForGenericType(type: InstantiableType | UnionOrIntersectionType, indexFlags: IndexFlags) {
|
||||
return indexFlags & IndexFlags.StringsOnly ?
|
||||
type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, IndexFlags.StringsOnly)) :
|
||||
type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, IndexFlags.None));
|
||||
const persistentFlags = indexFlags & (IndexFlags.StringsOnly | IndexFlags.FromIntersection);
|
||||
const key = `K${getTypeId(type)},${persistentFlags}`;
|
||||
return getCachedType(key) ?? setCachedType(key, createIndexType(type, persistentFlags));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18211,11 +18211,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return isNoInferType(type) ? getNoInferType(getIndexType((type as SubstitutionType).baseType, indexFlags)) :
|
||||
shouldDeferIndexType(type, indexFlags) ? getIndexTypeForGenericType(type as InstantiableType | UnionOrIntersectionType, indexFlags) :
|
||||
type.flags & TypeFlags.Union ? getIntersectionType(map((type as UnionType).types, t => getIndexType(t, indexFlags))) :
|
||||
type.flags & TypeFlags.Intersection ? getUnionType(map((type as IntersectionType).types, t => getIndexType(t, indexFlags))) :
|
||||
type.flags & TypeFlags.Intersection ? getUnionType(map((type as IntersectionType).types, t => getIndexType(t, indexFlags | IndexFlags.FromIntersection))) :
|
||||
getObjectFlags(type) & ObjectFlags.Mapped ? getIndexTypeForMappedType(type as MappedType, indexFlags) :
|
||||
type === wildcardType ? wildcardType :
|
||||
type.flags & TypeFlags.Unknown ? neverType :
|
||||
type.flags & (TypeFlags.Any | TypeFlags.Never) ? stringNumberSymbolType :
|
||||
type.flags & (TypeFlags.Any | TypeFlags.Never) || type.flags & TypeFlags.Nullable && indexFlags & IndexFlags.FromIntersection ? stringNumberSymbolType :
|
||||
getLiteralTypeFromProperties(type, (indexFlags & IndexFlags.NoIndexSignatures ? TypeFlags.StringLiteral : TypeFlags.StringLike) | (indexFlags & IndexFlags.StringsOnly ? 0 : TypeFlags.NumberLike | TypeFlags.ESSymbolLike), indexFlags === IndexFlags.None);
|
||||
}
|
||||
|
||||
@@ -20286,7 +20286,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
getUnionType(newTypes, UnionReduction.Literal, newAliasSymbol, newAliasTypeArguments);
|
||||
}
|
||||
if (flags & TypeFlags.Index) {
|
||||
return getIndexType(instantiateType((type as IndexType).type, mapper));
|
||||
return getIndexType(instantiateType((type as IndexType).type, mapper), (type as IndexType).indexFlags);
|
||||
}
|
||||
if (flags & TypeFlags.TemplateLiteral) {
|
||||
return getTemplateLiteralType((type as TemplateLiteralType).texts, instantiateTypes((type as TemplateLiteralType).types, mapper));
|
||||
|
||||
@@ -6569,10 +6569,6 @@ export interface SyntheticDefaultModuleType extends Type {
|
||||
export interface InstantiableType extends Type {
|
||||
/** @internal */
|
||||
resolvedBaseConstraint?: Type;
|
||||
/** @internal */
|
||||
resolvedIndexType?: IndexType;
|
||||
/** @internal */
|
||||
resolvedStringIndexType?: IndexType;
|
||||
}
|
||||
|
||||
// Type parameters (TypeFlags.TypeParameter)
|
||||
@@ -6629,8 +6625,9 @@ export type TypeVariable = TypeParameter | IndexedAccessType;
|
||||
export const enum IndexFlags {
|
||||
None = 0,
|
||||
StringsOnly = 1 << 0,
|
||||
NoIndexSignatures = 1 << 1,
|
||||
NoReducibleCheck = 1 << 2,
|
||||
FromIntersection = 1 << 1,
|
||||
NoIndexSignatures = 1 << 2,
|
||||
NoReducibleCheck = 1 << 3,
|
||||
}
|
||||
|
||||
// keyof T types (TypeFlags.Index)
|
||||
|
||||
Reference in New Issue
Block a user