mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Handle shorthand property assignments
This commit is contained in:
parent
019f5bd4e8
commit
f13c92f036
@ -7358,7 +7358,7 @@ namespace ts {
|
||||
return createArrayType(elementType);
|
||||
}
|
||||
|
||||
function getAssignedTypeOfPropertyAssignment(node: PropertyAssignment): Type {
|
||||
function getAssignedTypeOfPropertyAssignment(node: PropertyAssignment | ShorthandPropertyAssignment): Type {
|
||||
const objectType = getAssignedType(<ObjectLiteralExpression>node.parent);
|
||||
const text = getTextOfPropertyName(node.name);
|
||||
return getTypeOfPropertyOfType(objectType, text) ||
|
||||
@ -7367,6 +7367,15 @@ namespace ts {
|
||||
unknownType;
|
||||
}
|
||||
|
||||
function getAssignedTypeOfShorthandPropertyAssignment(node: ShorthandPropertyAssignment): Type {
|
||||
if (node.objectAssignmentInitializer) {
|
||||
const defaultType = checkExpressionCached(node.objectAssignmentInitializer);
|
||||
const assignedType = getAssignedTypeOfPropertyAssignment(node);
|
||||
return getUnionType([getTypeWithFacts(assignedType, TypeFacts.NEUndefined), defaultType]);
|
||||
}
|
||||
return getAssignedTypeOfPropertyAssignment(node);
|
||||
}
|
||||
|
||||
function getAssignedType(node: Expression): Type {
|
||||
const parent = node.parent;
|
||||
switch (parent.kind) {
|
||||
@ -7383,7 +7392,7 @@ namespace ts {
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return getAssignedTypeOfPropertyAssignment(<PropertyAssignment>parent);
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
break; // !!! TODO
|
||||
return getAssignedTypeOfShorthandPropertyAssignment(<ShorthandPropertyAssignment>parent);
|
||||
}
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
@ -1329,7 +1329,7 @@ namespace ts {
|
||||
node = parent;
|
||||
continue;
|
||||
}
|
||||
if (parent.kind === SyntaxKind.PropertyAssignment) {
|
||||
if (parent.kind === SyntaxKind.PropertyAssignment || parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
node = parent.parent;
|
||||
continue;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user