Skip to content

Commit d739c36

Browse files
author
Kanchalai Tanglertsampan
committed
Create base interface for ObjectLiteralExpression or future JSXAttributes to extend from.
Create ObjectLiteralElementLike and make ObjectLiteralElement become union type of all possible type allow in PropertyDefinition
1 parent 95c3ecc commit d739c36

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/compiler/types.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,23 @@ namespace ts {
643643
initializer?: Expression; // Optional initializer
644644
}
645645

646-
export interface ObjectLiteralElement extends Declaration {
646+
export interface ObjectLiteralElementLike extends Declaration {
647647
_objectLiteralBrandBrand: any;
648648
name?: PropertyName;
649649
}
650650

651+
export type ObjectLiteralElement = PropertyAssignment | ShorthandPropertyAssignment | SpreadObjectLiteralAssignment | MethodDeclaration | AccessorDeclaration;
652+
651653
// @kind(SyntaxKind.PropertyAssignment)
652-
export interface PropertyAssignment extends ObjectLiteralElement {
654+
export interface PropertyAssignment extends ObjectLiteralElementLike {
653655
_propertyAssignmentBrand: any;
654656
name: PropertyName;
655657
questionToken?: Node;
656658
initializer: Expression;
657659
}
658660

659661
// @kind(SyntaxKind.ShorthandPropertyAssignment)
660-
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
662+
export interface ShorthandPropertyAssignment extends ObjectLiteralElementLike {
661663
name: Identifier;
662664
questionToken?: Node;
663665
// used when ObjectLiteralExpression is used in ObjectAssignmentPattern
@@ -740,7 +742,7 @@ namespace ts {
740742
// at later stages of the compiler pipeline. In that case, you can either check the parent kind
741743
// of the method, or use helpers like isObjectLiteralMethodDeclaration
742744
// @kind(SyntaxKind.MethodDeclaration)
743-
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
745+
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElementLike {
744746
name: PropertyName;
745747
body?: FunctionBody;
746748
}
@@ -758,7 +760,7 @@ namespace ts {
758760

759761
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
760762
// ClassElement and an ObjectLiteralElement.
761-
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
763+
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElementLike {
762764
_accessorDeclarationBrand: any;
763765
name: PropertyName;
764766
body: FunctionBody;
@@ -1048,10 +1050,16 @@ namespace ts {
10481050
expression: Expression;
10491051
}
10501052

1053+
// The reason we create this interface so that JSXAttributes and ObjectLiteralExpression interface can extend out of it.
1054+
// JSXAttributes differs from normal ObjectLiteralExpression in that JSXAttributes can only take JSXAttribute or JSXSpreadAttribute
1055+
// but not ShortHandPropertyAssignment, methodDeclaration or other ObjectLiteralElementLike acceptable by ObjectLiteralExpression.
1056+
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElementLike> extends PrimaryExpression, Declaration {
1057+
properties: NodeArray<T>;
1058+
}
1059+
10511060
// An ObjectLiteralExpression is the declaration node for an anonymous symbol.
10521061
// @kind(SyntaxKind.ObjectLiteralExpression)
1053-
export interface ObjectLiteralExpression extends PrimaryExpression, Declaration {
1054-
properties: NodeArray<ObjectLiteralElement>;
1062+
export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElement>{
10551063
/* @internal */
10561064
multiLine?: boolean;
10571065
}
@@ -1195,7 +1203,7 @@ namespace ts {
11951203
export interface DebuggerStatement extends Statement { }
11961204

11971205
// @kind(SyntaxKind.MissingDeclaration)
1198-
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement {
1206+
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElementLike, TypeElement {
11991207
name?: Identifier;
12001208
}
12011209

0 commit comments

Comments
 (0)