Skip to content

Commit a292da5

Browse files
committed
Check if binding element already has been assigned a contextual type
1 parent 5a77d67 commit a292da5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/compiler/checker.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2293,10 +2293,17 @@ namespace ts {
22932293
return type && (type.flags & TypeFlags.Any) !== 0;
22942294
}
22952295

2296+
// Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
2297+
// assigned by contextual typing.
2298+
function getTypeForBindingElementParent(node: VariableLikeDeclaration) {
2299+
let symbol = getSymbolOfNode(node);
2300+
return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
2301+
}
2302+
22962303
// Return the inferred type for a binding element
22972304
function getTypeForBindingElement(declaration: BindingElement): Type {
22982305
let pattern = <BindingPattern>declaration.parent;
2299-
let parentType = getTypeForVariableLikeDeclaration(<VariableLikeDeclaration>pattern.parent);
2306+
let parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
23002307
// If parent has the unknown (error) type, then so does this binding element
23012308
if (parentType === unknownType) {
23022309
return unknownType;

0 commit comments

Comments
 (0)