diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56a36f658d719..bc4f466c4cc7f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43067,7 +43067,7 @@ namespace ts { if (prop.kind === SyntaxKind.ShorthandPropertyAssignment && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern // outside of destructuring it is a syntax error - return grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern); + grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern); } if (name.kind === SyntaxKind.PrivateIdentifier) { diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 3c0229297829f..972e2a5524150 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -74,9 +74,12 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(48,7): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(49,7): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5): error TS18016: Private identifiers are not allowed outside class bodies. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; ~ @@ -273,4 +276,17 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16) var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; ~ !!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type + + // did you mean colon errors + var h1 = { + x = 1, + ~ +!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern. + y = 2, + ~ +!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern. + #z: 3 + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralErrors.js b/tests/baselines/reference/objectLiteralErrors.js index 1f721d3e71ce1..576e23b0b78d0 100644 --- a/tests/baselines/reference/objectLiteralErrors.js +++ b/tests/baselines/reference/objectLiteralErrors.js @@ -43,6 +43,13 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a(): number { return 4; }, set a(n: string) { } }; var g2 = { get a() { return 4; }, set a(n: string) { } }; var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; + +// did you mean colon errors +var h1 = { + x = 1, + y = 2, + #z: 3 +} //// [objectLiteralErrors.js] @@ -88,3 +95,9 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a() { return 4; }, set a(n) { } }; var g2 = { get a() { return 4; }, set a(n) { } }; var g3 = { get a() { return undefined; }, set a(n) { } }; +// did you mean colon errors +var h1 = { + x: x, + y: y, + : 3 +}; diff --git a/tests/baselines/reference/objectLiteralErrors.symbols b/tests/baselines/reference/objectLiteralErrors.symbols index 94600906a2a15..f2d19b661ebbb 100644 --- a/tests/baselines/reference/objectLiteralErrors.symbols +++ b/tests/baselines/reference/objectLiteralErrors.symbols @@ -203,3 +203,17 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; >a : Symbol(a, Decl(objectLiteralErrors.ts, 43, 10), Decl(objectLiteralErrors.ts, 43, 49)) >n : Symbol(n, Decl(objectLiteralErrors.ts, 43, 56)) +// did you mean colon errors +var h1 = { +>h1 : Symbol(h1, Decl(objectLiteralErrors.ts, 46, 3)) + + x = 1, +>x : Symbol(x, Decl(objectLiteralErrors.ts, 46, 10)) + + y = 2, +>y : Symbol(y, Decl(objectLiteralErrors.ts, 47, 10)) + + #z: 3 +>#z : Symbol(#z, Decl(objectLiteralErrors.ts, 48, 10)) +} + diff --git a/tests/baselines/reference/objectLiteralErrors.types b/tests/baselines/reference/objectLiteralErrors.types index 271b657fd630e..47631d9b1aed3 100644 --- a/tests/baselines/reference/objectLiteralErrors.types +++ b/tests/baselines/reference/objectLiteralErrors.types @@ -318,3 +318,21 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; >a : number >n : string +// did you mean colon errors +var h1 = { +>h1 : { x: number; y: number; } +>{ x = 1, y = 2, #z: 3} : { x: number; y: number; } + + x = 1, +>x : any +>1 : 1 + + y = 2, +>y : any +>2 : 2 + + #z: 3 +>#z : number +>3 : 3 +} + diff --git a/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts b/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts index 209b56eed6de5..b95f12b6d14cf 100644 --- a/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts +++ b/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts @@ -44,3 +44,10 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a(): number { return 4; }, set a(n: string) { } }; var g2 = { get a() { return 4; }, set a(n: string) { } }; var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; + +// did you mean colon errors +var h1 = { + x = 1, + y = 2, + #z: 3 +}