Use binding pattern for type inference result {}

The binding pattern provides additional information when the contextual
type is not found and would otherwise fix a type parameter to `{}`.
This commit is contained in:
Nathan Shively-Sanders
2016-05-16 16:09:36 -07:00
parent ef75346e7e
commit ae4a983c59
5 changed files with 104 additions and 0 deletions

View File

@@ -11455,6 +11455,12 @@ namespace ts {
const links = getSymbolLinks(parameter);
if (!links.type) {
links.type = instantiateType(contextualType, mapper);
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
if (links.type === emptyObjectType &&
(parameter.valueDeclaration.name.kind === SyntaxKind.ObjectBindingPattern ||
parameter.valueDeclaration.name.kind === SyntaxKind.ArrayBindingPattern)) {
links.type = getTypeFromBindingPattern(<BindingPattern>parameter.valueDeclaration.name);
}
assignBindingElementTypes(<ParameterDeclaration>parameter.valueDeclaration);
}
else if (isInferentialContext(mapper)) {