From 364142c06235b58cf14df7e2c1c927a76adeb75b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 11 Nov 2016 07:39:51 -0800 Subject: [PATCH] Improve type inference for types with same generic type alias --- src/compiler/checker.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 90d6078c8c9..01ea2227217 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8318,6 +8318,16 @@ namespace ts { if (!couldContainTypeParameters(target)) { return; } + if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) { + // Source and target are types originating in the same generic type alias declaration. + // Simply infer from source type arguments to target type arguments. + const sourceTypes = source.aliasTypeArguments; + const targetTypes = target.aliasTypeArguments; + for (let i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], targetTypes[i]); + } + return; + } if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union && !(source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { // Source and target are both unions or both intersections. If source and target