Skip to content

Commit 33aeffb

Browse files
committed
Improve type inference to allow HKT technique function again
1 parent 94564cf commit 33aeffb

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17685,7 +17685,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1768517685
// eagerly using the constraint type of 'this' at the given location.
1768617686
if (isGenericIndexType(indexType) || (accessNode && accessNode.kind !== SyntaxKind.IndexedAccessType ?
1768717687
isGenericTupleType(objectType) && !indexTypeLessThan(indexType, objectType.target.fixedLength) :
17688-
isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, objectType.target.fixedLength)) || isGenericReducibleType(objectType))) {
17688+
isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, objectType.target.fixedLength)) || !(accessFlags & AccessFlags.ResolveReducibleTypes) && isGenericReducibleType(objectType))) {
1768917689
if (objectType.flags & TypeFlags.AnyOrUnknown) {
1769017690
return objectType;
1769117691
}
@@ -24511,6 +24511,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2451124511
}
2451224512
}
2451324513
}
24514+
// The following is a targeted fix to allow higher-kinded types to be emulated using the technique in #53970.
24515+
// Specifically, when an indexed access type was deferred because it has a reducible object type, here we force
24516+
// resolution of the type and then infer to the result.
24517+
if (target.flags & TypeFlags.IndexedAccess && isGenericReducibleType((target as IndexedAccessType).objectType)) {
24518+
const instantiated = getIndexedAccessType((target as IndexedAccessType).objectType, (target as IndexedAccessType).indexType, AccessFlags.ResolveReducibleTypes);
24519+
if (instantiated && instantiated !== target) {
24520+
inferFromTypes(source, instantiated);
24521+
}
24522+
}
2451424523
}
2451524524
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (
2451624525
(source as TypeReference).target === (target as TypeReference).target || isArrayType(source) && isArrayType(target)) &&

src/compiler/types.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6593,15 +6593,16 @@ export interface TypeParameter extends InstantiableType {
65936593
export const enum AccessFlags {
65946594
None = 0,
65956595
IncludeUndefined = 1 << 0,
6596-
NoIndexSignatures = 1 << 1,
6597-
Writing = 1 << 2,
6598-
CacheSymbol = 1 << 3,
6599-
NoTupleBoundsCheck = 1 << 4,
6600-
ExpressionPosition = 1 << 5,
6601-
ReportDeprecated = 1 << 6,
6602-
SuppressNoImplicitAnyError = 1 << 7,
6603-
Contextual = 1 << 8,
6604-
Persistent = IncludeUndefined,
6596+
ResolveReducibleTypes = 1 << 1,
6597+
NoIndexSignatures = 1 << 2,
6598+
Writing = 1 << 3,
6599+
CacheSymbol = 1 << 4,
6600+
NoTupleBoundsCheck = 1 << 5,
6601+
ExpressionPosition = 1 << 6,
6602+
ReportDeprecated = 1 << 7,
6603+
SuppressNoImplicitAnyError = 1 << 8,
6604+
Contextual = 1 << 9,
6605+
Persistent = IncludeUndefined | ResolveReducibleTypes,
66056606
}
66066607

66076608
// Indexed access types (TypeFlags.IndexedAccess)

0 commit comments

Comments
 (0)