Add ability to infer to the simplified form of a type variable (#27953)

* Add ability to infer to the simplified form of a type variable

* Add test
This commit is contained in:
Wesley Wigham
2018-10-17 14:44:39 -07:00
committed by GitHub
parent 7b5ef64e76
commit 9554f09d09
5 changed files with 189 additions and 0 deletions

View File

@@ -13644,6 +13644,17 @@ namespace ts {
}
return;
}
else {
// Infer to the simplified version of an indexed access, if possible, to (hopefully) expose more bare type parameters to the inference engine
const simplified = getSimplifiedType(target);
if (simplified !== target) {
const key = source.id + "," + simplified.id;
if (!visited || !visited.get(key)) {
(visited || (visited = createMap<boolean>())).set(key, true);
inferFromTypes(source, simplified);
}
}
}
}
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// If source and target are references to the same generic type, infer from type arguments