Skip to content

Commit 364142c

Browse files
committed
Improve type inference for types with same generic type alias
1 parent 1c7ec6b commit 364142c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8318,6 +8318,16 @@ namespace ts {
83188318
if (!couldContainTypeParameters(target)) {
83198319
return;
83208320
}
8321+
if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
8322+
// Source and target are types originating in the same generic type alias declaration.
8323+
// Simply infer from source type arguments to target type arguments.
8324+
const sourceTypes = source.aliasTypeArguments;
8325+
const targetTypes = target.aliasTypeArguments;
8326+
for (let i = 0; i < sourceTypes.length; i++) {
8327+
inferFromTypes(sourceTypes[i], targetTypes[i]);
8328+
}
8329+
return;
8330+
}
83218331
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union && !(source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) ||
83228332
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
83238333
// Source and target are both unions or both intersections. If source and target

0 commit comments

Comments
 (0)