Skip to content

Commit 712e7bf

Browse files
authored
Merge pull request microsoft#10568 from Microsoft/parse-untyped-object-type-members-comma-separated
Parse untyped object type members comma separated
2 parents b0f7f2f + 3f8cd82 commit 712e7bf

11 files changed

+61
-33
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ namespace ts {
23392339
token() === SyntaxKind.LessThanToken ||
23402340
token() === SyntaxKind.QuestionToken ||
23412341
token() === SyntaxKind.ColonToken ||
2342+
token() === SyntaxKind.CommaToken ||
23422343
canParseSemicolon();
23432344
}
23442345
return false;

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(4,43): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
22
Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'.
3-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected.
4-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
5-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected.
63
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.
74
Types of property 'id' are incompatible.
85
Type 'number' is not assignable to type 'string'.
@@ -11,21 +8,15 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
118
Type 'number' is not assignable to type 'boolean'.
129

1310

14-
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (6 errors) ====
11+
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (3 errors) ====
1512
var id: number = 10000;
1613
var name: string = "my name";
1714

1815
var person: { b: string; id: number } = { name, id }; // error
1916
~~~~
2017
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
2118
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'.
22-
var person1: { name, id }; // error: can't use short-hand property assignment in type position
23-
~~~~
24-
!!! error TS1131: Property or signature expected.
25-
~~
26-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
27-
~
28-
!!! error TS1128: Declaration or statement expected.
19+
var person1: { name, id }; // ok
2920
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
3021
~~~~~~~~~~~~
3122
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var id: number = 10000;
33
var name: string = "my name";
44

55
var person: { b: string; id: number } = { name, id }; // error
6-
var person1: { name, id }; // error: can't use short-hand property assignment in type position
6+
var person1: { name, id }; // ok
77
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
88
function bar(obj: { name: string; id: boolean }) { }
99
bar({ name, id }); // error
@@ -14,8 +14,7 @@ bar({ name, id }); // error
1414
var id = 10000;
1515
var name = "my name";
1616
var person = { name: name, id: id }; // error
17-
var person1 = name, id;
18-
; // error: can't use short-hand property assignment in type position
17+
var person1; // ok
1918
function foo(name, id) { return { name: name, id: id }; } // error
2019
function bar(obj) { }
2120
bar({ name: name, id: id }); // error

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
33
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'.
44
Types of property 'name' are incompatible.
55
Type 'string' is not assignable to type 'number'.
6-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,16): error TS1131: Property or signature expected.
7-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
8-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,25): error TS1128: Declaration or statement expected.
96
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,5): error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
107
Types of property 'name' are incompatible.
118
Type 'number' is not assignable to type 'string'.
129

1310

14-
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (6 errors) ====
11+
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (3 errors) ====
1512
var id: number = 10000;
1613
var name: string = "my name";
1714

@@ -25,15 +22,10 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
2522
!!! error TS2322: Types of property 'name' are incompatible.
2623
!!! error TS2322: Type 'string' is not assignable to type 'number'.
2724
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
28-
var person1: { name, id }; // error : Can't use shorthand in the type position
29-
~~~~
30-
!!! error TS1131: Property or signature expected.
31-
~~
32-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
33-
~
34-
!!! error TS1128: Declaration or statement expected.
25+
var person1: { name, id }; // ok
3526
var person2: { name: string, id: number } = bar("hello", 5);
3627
~~~~~~~
3728
!!! error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
3829
!!! error TS2322: Types of property 'name' are incompatible.
39-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
30+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
31+

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ var name: string = "my name";
55
var person: { b: string; id: number } = { name, id }; // error
66
function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error
77
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
8-
var person1: { name, id }; // error : Can't use shorthand in the type position
9-
var person2: { name: string, id: number } = bar("hello", 5);
8+
var person1: { name, id }; // ok
9+
var person2: { name: string, id: number } = bar("hello", 5);
10+
1011

1112
//// [objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js]
1213
var id = 10000;
1314
var name = "my name";
1415
var person = { name: name, id: id }; // error
1516
function bar(name, id) { return { name: name, id: id }; } // error
1617
function foo(name, id) { return { name: name, id: id }; } // error
17-
var person1 = name, id;
18-
; // error : Can't use shorthand in the type position
18+
var person1; // ok
1919
var person2 = bar("hello", 5);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [parseObjectLiteralsWithoutTypes.ts]
2+
let x: { foo, bar }
3+
let y: { foo: number, bar }
4+
let z: { foo, bar: number }
5+
6+
7+
//// [parseObjectLiteralsWithoutTypes.js]
8+
var x;
9+
var y;
10+
var z;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts ===
2+
let x: { foo, bar }
3+
>x : Symbol(x, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 3))
4+
>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 8))
5+
>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 13))
6+
7+
let y: { foo: number, bar }
8+
>y : Symbol(y, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 3))
9+
>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 8))
10+
>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 21))
11+
12+
let z: { foo, bar: number }
13+
>z : Symbol(z, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 3))
14+
>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 8))
15+
>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 13))
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts ===
2+
let x: { foo, bar }
3+
>x : { foo: any; bar: any; }
4+
>foo : any
5+
>bar : any
6+
7+
let y: { foo: number, bar }
8+
>y : { foo: number; bar: any; }
9+
>foo : number
10+
>bar : any
11+
12+
let z: { foo, bar: number }
13+
>z : { foo: any; bar: number; }
14+
>foo : any
15+
>bar : number
16+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let x: { foo, bar }
2+
let y: { foo: number, bar }
3+
let z: { foo, bar: number }

tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var name: string = "my name";
33

44
var person: { b: string; id: number } = { name, id }; // error
5-
var person1: { name, id }; // error: can't use short-hand property assignment in type position
5+
var person1: { name, id }; // ok
66
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
77
function bar(obj: { name: string; id: boolean }) { }
88
bar({ name, id }); // error

tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ var name: string = "my name";
44
var person: { b: string; id: number } = { name, id }; // error
55
function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error
66
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
7-
var person1: { name, id }; // error : Can't use shorthand in the type position
8-
var person2: { name: string, id: number } = bar("hello", 5);
7+
var person1: { name, id }; // ok
8+
var person2: { name: string, id: number } = bar("hello", 5);

0 commit comments

Comments
 (0)