From a292da593bb4d059c84b0510b8b234dbe448119c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 23 Sep 2015 14:45:09 -0700 Subject: [PATCH] Check if binding element already has been assigned a contextual type --- src/compiler/checker.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2aee597092d..b0a695e1e7d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2293,10 +2293,17 @@ namespace ts { return type && (type.flags & TypeFlags.Any) !== 0; } + // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been + // assigned by contextual typing. + function getTypeForBindingElementParent(node: VariableLikeDeclaration) { + let symbol = getSymbolOfNode(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + } + // Return the inferred type for a binding element function getTypeForBindingElement(declaration: BindingElement): Type { let pattern = declaration.parent; - let parentType = getTypeForVariableLikeDeclaration(pattern.parent); + let parentType = getTypeForBindingElementParent(pattern.parent); // If parent has the unknown (error) type, then so does this binding element if (parentType === unknownType) { return unknownType;