Contextual typing checks property assignments for type annotation (#43598)

Property assignments can have a type annotation in JS. This PR adds a
check for it in contextual typing.

Fixes #43379
This commit is contained in:
Nathan Shively-Sanders
2021-04-26 09:19:24 -07:00
committed by GitHub
parent b9c1e98544
commit d5af89c552
4 changed files with 71 additions and 0 deletions
+4
View File
@@ -25218,6 +25218,10 @@ namespace ts {
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike, contextFlags?: ContextFlags) {
const objectLiteral = <ObjectLiteralExpression>element.parent;
const propertyAssignmentType = isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element);
if (propertyAssignmentType) {
return propertyAssignmentType;
}
const type = getApparentTypeOfContextualType(objectLiteral, contextFlags);
if (type) {
if (hasBindableName(element)) {