diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8ff6712ad30ac..5ed5bf12c43d9 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2066,12 +2066,6 @@ namespace ts { seen.set(identifier.escapedText, currentKind); continue; } - - if (currentKind === ElementKind.Property && existingKind === ElementKind.Property) { - const span = getErrorSpanForNode(file, identifier); - file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, - Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode)); - } } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 25afc98fc4eb2..e7c4bae3d00d6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43126,9 +43126,12 @@ namespace ts { seen.set(effectiveName, currentKind); } else { - if ((currentKind & DeclarationMeaning.PropertyAssignmentOrMethod) && (existingKind & DeclarationMeaning.PropertyAssignmentOrMethod)) { + if ((currentKind & DeclarationMeaning.Method) && (existingKind & DeclarationMeaning.Method)) { grammarErrorOnNode(name, Diagnostics.Duplicate_identifier_0, getTextOfNode(name)); } + else if ((currentKind & DeclarationMeaning.PropertyAssignment) && (existingKind & DeclarationMeaning.PropertyAssignment)) { + grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name, getTextOfNode(name)); + } else if ((currentKind & DeclarationMeaning.GetOrSetAccessor) && (existingKind & DeclarationMeaning.GetOrSetAccessor)) { if (existingKind !== DeclarationMeaning.GetOrSetAccessor && currentKind !== existingKind) { seen.set(effectiveName, currentKind | existingKind); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 17e8a5550f2b8..d8f1a1b5312d3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -335,7 +335,7 @@ "category": "Error", "code": 1116 }, - "An object literal cannot have multiple properties with the same name in strict mode.": { + "An object literal cannot have multiple properties with the same name.": { "category": "Error", "code": 1117 }, diff --git a/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt b/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt index fda0f4a66d98a..9b69963bd05f4 100644 --- a/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierDifferentSpelling.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(3,3): error TS2300: Duplicate identifier '3'. -tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(6,21): error TS2300: Duplicate identifier '3'. +tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(6,21): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts (2 errors) ==== @@ -12,5 +12,5 @@ tests/cases/compiler/duplicateIdentifierDifferentSpelling.ts(6,21): error TS2300 var X = { 0b11: '', 3: '' }; ~ -!!! error TS2300: Duplicate identifier '3'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. \ No newline at end of file diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt index abc56a6f8fce7..1e577a7dedd6c 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt +++ b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/duplicateObjectLiteralProperty.ts(4,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(5,5): error TS2300: Duplicate identifier '\u0061'. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(6,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(8,9): error TS2300: Duplicate identifier '"c"'. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(4,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(5,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(6,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty.ts(8,9): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/compiler/duplicateObjectLiteralProperty.ts(14,9): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(15,9): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name. @@ -14,17 +14,17 @@ tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS2300: Dupl b: true, // OK a: 56, // Duplicate ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. \u0061: "ss", // Duplicate ~~~~~~ -!!! error TS2300: Duplicate identifier '\u0061'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. a: { ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. c: 1, "c": 56, // Duplicate ~~~ -!!! error TS2300: Duplicate identifier '"c"'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } }; diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt index 84fae4c8fbe8a..af508272d8462 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedName.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(3,5): error TS2300: Duplicate identifier '[1]'. -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(8,5): error TS2300: Duplicate identifier '[+1]'. -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(13,5): error TS2300: Duplicate identifier '[+1]'. -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(23,5): error TS2300: Duplicate identifier '["+1"]'. -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(28,5): error TS2300: Duplicate identifier '[-1]'. -tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error TS2300: Duplicate identifier '["-1"]'. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(3,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(8,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(13,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(23,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(28,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts (6 errors) ==== @@ -11,21 +11,21 @@ tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error 1: 1, [1]: 0 // duplicate ~~~ -!!! error TS2300: Duplicate identifier '[1]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } const t2 = { 1: 1, [+1]: 0 // duplicate ~~~~ -!!! error TS2300: Duplicate identifier '[+1]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } const t3 = { "1": 1, [+1]: 0 // duplicate ~~~~ -!!! error TS2300: Duplicate identifier '[+1]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } const t4 = { @@ -37,20 +37,20 @@ tests/cases/compiler/duplicateObjectLiteralProperty_computedName.ts(33,5): error "+1": 1, ["+1"]: 0 // duplicate ~~~~~~ -!!! error TS2300: Duplicate identifier '["+1"]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } const t6 = { "-1": 1, [-1]: 0 // duplicate ~~~~ -!!! error TS2300: Duplicate identifier '[-1]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } const t7 = { "-1": 1, ["-1"]: 0 // duplicate ~~~~~~ -!!! error TS2300: Duplicate identifier '["-1"]'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } \ No newline at end of file diff --git a/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt b/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt index 17a55a7876b00..06adca996f8db 100644 --- a/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt +++ b/tests/baselines/reference/duplicatePropertiesInStrictMode.errors.txt @@ -1,14 +1,11 @@ -tests/cases/compiler/duplicatePropertiesInStrictMode.ts(4,3): error TS1117: An object literal cannot have multiple properties with the same name in strict mode. -tests/cases/compiler/duplicatePropertiesInStrictMode.ts(4,3): error TS2300: Duplicate identifier 'x'. +tests/cases/compiler/duplicatePropertiesInStrictMode.ts(4,3): error TS1117: An object literal cannot have multiple properties with the same name. -==== tests/cases/compiler/duplicatePropertiesInStrictMode.ts (2 errors) ==== +==== tests/cases/compiler/duplicatePropertiesInStrictMode.ts (1 errors) ==== "use strict"; var x = { x: 1, x: 2 ~ -!!! error TS1117: An object literal cannot have multiple properties with the same name in strict mode. - ~ -!!! error TS2300: Duplicate identifier 'x'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } \ No newline at end of file diff --git a/tests/baselines/reference/duplicatePropertyNames.errors.txt b/tests/baselines/reference/duplicatePropertyNames.errors.txt index f8ed73c570740..8c163a99e9d26 100644 --- a/tests/baselines/reference/duplicatePropertyNames.errors.txt +++ b/tests/baselines/reference/duplicatePropertyNames.errors.txt @@ -12,8 +12,8 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(35,5): error TS2 tests/cases/conformance/types/members/duplicatePropertyNames.ts(36,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(38,5): error TS2300: Duplicate identifier 'bar'. tests/cases/conformance/types/members/duplicatePropertyNames.ts(39,5): error TS2300: Duplicate identifier 'bar'. -tests/cases/conformance/types/members/duplicatePropertyNames.ts(44,5): error TS2300: Duplicate identifier 'foo'. -tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2300: Duplicate identifier 'bar'. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(44,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/conformance/types/members/duplicatePropertyNames.ts (16 errors) ==== @@ -90,10 +90,10 @@ tests/cases/conformance/types/members/duplicatePropertyNames.ts(46,5): error TS2 foo: '', foo: '', ~~~ -!!! error TS2300: Duplicate identifier 'foo'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. bar: () => { }, bar: () => { } ~~~ -!!! error TS2300: Duplicate identifier 'bar'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt index 09020d7982eba..64fc50e8307c7 100644 --- a/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt @@ -1,5 +1,4 @@ -tests/cases/compiler/a.js(5,5): error TS1117: An object literal cannot have multiple properties with the same name in strict mode. -tests/cases/compiler/a.js(5,5): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/a.js(5,5): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/compiler/a.js(7,5): error TS1212: Identifier expected. 'let' is a reserved word in strict mode. tests/cases/compiler/a.js(8,8): error TS1102: 'delete' cannot be called on an identifier in strict mode. tests/cases/compiler/a.js(8,8): error TS2703: The operand of a 'delete' operator must be a property reference. @@ -15,16 +14,14 @@ tests/cases/compiler/d.js(2,9): error TS1121: Octal literals are not allowed in tests/cases/compiler/d.js(2,11): error TS1005: ',' expected. -==== tests/cases/compiler/a.js (9 errors) ==== +==== tests/cases/compiler/a.js (8 errors) ==== "use strict"; var a = { a: "hello", // error b: 10, a: 10 // error ~ -!!! error TS1117: An object literal cannot have multiple properties with the same name in strict mode. - ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. }; var let = 10; // error ~~~ diff --git a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt index 5e12521ad6064..ad10095d2581a 100644 --- a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt +++ b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt @@ -1,9 +1,9 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. Types of parameters 'num' and 'str' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. -tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/compiler/lastPropertyInLiteralWins.ts (4 errors) ==== @@ -22,7 +22,7 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate !!! related TS6500 tests/cases/compiler/lastPropertyInLiteralWins.ts:2:5: The expected type comes from property 'thunk' which is declared here on type 'Thing' thunk: (num: number) => {} ~~~~~ -!!! error TS2300: Duplicate identifier 'thunk'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. ~~~~~ !!! error TS2322: Type '(num: number) => void' is not assignable to type '(str: string) => void'. !!! related TS6500 tests/cases/compiler/lastPropertyInLiteralWins.ts:2:5: The expected type comes from property 'thunk' which is declared here on type 'Thing' @@ -32,6 +32,6 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate thunk: (num: number) => {}, thunk: (str: string) => {} ~~~~~ -!!! error TS2300: Duplicate identifier 'thunk'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. }); \ No newline at end of file diff --git a/tests/baselines/reference/memberOverride.errors.txt b/tests/baselines/reference/memberOverride.errors.txt index 15c4b2ad37bb8..63d28ba75c2f1 100644 --- a/tests/baselines/reference/memberOverride.errors.txt +++ b/tests/baselines/reference/memberOverride.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/memberOverride.ts(5,5): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/memberOverride.ts(5,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/compiler/memberOverride.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/memberOverride.ts(5,5): error TS2300: Duplicate identifier a: "", a: 5 ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } var n: number = x.a; \ No newline at end of file diff --git a/tests/baselines/reference/noRepeatedPropertyNames.errors.txt b/tests/baselines/reference/noRepeatedPropertyNames.errors.txt new file mode 100644 index 0000000000000..991cfa56dfb69 --- /dev/null +++ b/tests/baselines/reference/noRepeatedPropertyNames.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/noRepeatedPropertyNames.ts(2,23): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/compiler/noRepeatedPropertyNames.ts(5,32): error TS1117: An object literal cannot have multiple properties with the same name. + + +==== tests/cases/compiler/noRepeatedPropertyNames.ts (2 errors) ==== + // https://github.com/microsoft/TypeScript/issues/46815 + const first = { a: 1, a: 2 }; + ~ +!!! error TS1117: An object literal cannot have multiple properties with the same name. + class C { + m() { + const second = { a: 1, a: 2 }; + ~ +!!! error TS1117: An object literal cannot have multiple properties with the same name. + return second.a; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/noRepeatedPropertyNames.js b/tests/baselines/reference/noRepeatedPropertyNames.js new file mode 100644 index 0000000000000..895e8c67240d6 --- /dev/null +++ b/tests/baselines/reference/noRepeatedPropertyNames.js @@ -0,0 +1,23 @@ +//// [noRepeatedPropertyNames.ts] +// https://github.com/microsoft/TypeScript/issues/46815 +const first = { a: 1, a: 2 }; +class C { + m() { + const second = { a: 1, a: 2 }; + return second.a; + } +} + + +//// [noRepeatedPropertyNames.js] +// https://github.com/microsoft/TypeScript/issues/46815 +var first = { a: 1, a: 2 }; +var C = /** @class */ (function () { + function C() { + } + C.prototype.m = function () { + var second = { a: 1, a: 2 }; + return second.a; + }; + return C; +}()); diff --git a/tests/baselines/reference/noRepeatedPropertyNames.symbols b/tests/baselines/reference/noRepeatedPropertyNames.symbols new file mode 100644 index 0000000000000..78d0fe4a4e3aa --- /dev/null +++ b/tests/baselines/reference/noRepeatedPropertyNames.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/noRepeatedPropertyNames.ts === +// https://github.com/microsoft/TypeScript/issues/46815 +const first = { a: 1, a: 2 }; +>first : Symbol(first, Decl(noRepeatedPropertyNames.ts, 1, 5)) +>a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 1, 15), Decl(noRepeatedPropertyNames.ts, 1, 21)) +>a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 1, 15), Decl(noRepeatedPropertyNames.ts, 1, 21)) + +class C { +>C : Symbol(C, Decl(noRepeatedPropertyNames.ts, 1, 29)) + + m() { +>m : Symbol(C.m, Decl(noRepeatedPropertyNames.ts, 2, 9)) + + const second = { a: 1, a: 2 }; +>second : Symbol(second, Decl(noRepeatedPropertyNames.ts, 4, 13)) +>a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 4, 24), Decl(noRepeatedPropertyNames.ts, 4, 30)) +>a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 4, 24), Decl(noRepeatedPropertyNames.ts, 4, 30)) + + return second.a; +>second.a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 4, 24), Decl(noRepeatedPropertyNames.ts, 4, 30)) +>second : Symbol(second, Decl(noRepeatedPropertyNames.ts, 4, 13)) +>a : Symbol(a, Decl(noRepeatedPropertyNames.ts, 4, 24), Decl(noRepeatedPropertyNames.ts, 4, 30)) + } +} + diff --git a/tests/baselines/reference/noRepeatedPropertyNames.types b/tests/baselines/reference/noRepeatedPropertyNames.types new file mode 100644 index 0000000000000..a32d0005a9409 --- /dev/null +++ b/tests/baselines/reference/noRepeatedPropertyNames.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/noRepeatedPropertyNames.ts === +// https://github.com/microsoft/TypeScript/issues/46815 +const first = { a: 1, a: 2 }; +>first : { a: number; } +>{ a: 1, a: 2 } : { a: number; } +>a : number +>1 : 1 +>a : number +>2 : 2 + +class C { +>C : C + + m() { +>m : () => number + + const second = { a: 1, a: 2 }; +>second : { a: number; } +>{ a: 1, a: 2 } : { a: number; } +>a : number +>1 : 1 +>a : number +>2 : 2 + + return second.a; +>second.a : number +>second : { a: number; } +>a : number + } +} + diff --git a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt index 7d3ff163300d5..4d2ad7178632a 100644 --- a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt +++ b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt @@ -4,7 +4,7 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericString tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(16,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(17,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(17,5): error TS2717: Subsequent property declarations must have the same type. Property '1.0' must be of type 'number', but here has type 'string'. -tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(22,5): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts(22,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts (7 errors) ==== @@ -44,5 +44,5 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericString "0": '', 0: '' ~ -!!! error TS2300: Duplicate identifier '0'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 2a6114ed0957e..3c0229297829f 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -1,22 +1,22 @@ -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(2,18): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,19): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,18): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(5,21): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(6,19): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(7,18): error TS2300: Duplicate identifier ''a''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(8,20): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(9,20): error TS2300: Duplicate identifier '"a"'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(10,20): error TS2300: Duplicate identifier ''a''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(11,21): error TS2300: Duplicate identifier ''a''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(12,21): error TS2300: Duplicate identifier ''1''. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,19): error TS2300: Duplicate identifier '0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,19): error TS2300: Duplicate identifier '0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS2300: Duplicate identifier '0x0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(2,18): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,19): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,18): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(5,21): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(6,19): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(7,18): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(8,20): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(9,20): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(10,20): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(11,21): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(12,21): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,19): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,19): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS2300: Duplicate identifier '000'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,23): error TS2300: Duplicate identifier '1e2'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,22): error TS2300: Duplicate identifier '3.2e1'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,25): error TS2300: Duplicate identifier 'a'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,23): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,22): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,25): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(22,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(22,22): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(22,22): error TS2300: Duplicate identifier 'a'. @@ -80,60 +80,60 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16) // Multiple properties with the same name var e1 = { a: 0, a: 0 }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e2 = { a: '', a: '' }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e3 = { a: 0, a: '' }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e4 = { a: true, a: false }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e5 = { a: {}, a: {} }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e6 = { a: 0, 'a': 0 }; ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e7 = { 'a': 0, a: 0 }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e8 = { 'a': 0, "a": 0 }; ~~~ -!!! error TS2300: Duplicate identifier '"a"'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e9 = { 'a': 0, 'a': 0 }; ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e10 = { "a": 0, 'a': 0 }; ~~~ -!!! error TS2300: Duplicate identifier ''a''. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e11 = { 1.0: 0, '1': 0 }; ~~~ -!!! error TS2300: Duplicate identifier ''1''. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e12 = { 0: 0, 0: 0 }; ~ -!!! error TS2300: Duplicate identifier '0'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e13 = { 0: 0, 0: 0 }; ~ -!!! error TS2300: Duplicate identifier '0'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e14 = { 0: 0, 0x0: 0 }; ~~~ -!!! error TS2300: Duplicate identifier '0x0'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e14 = { 0: 0, 000: 0 }; ~~~ !!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. ~~~ -!!! error TS2300: Duplicate identifier '000'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e15 = { "100": 0, 1e2: 0 }; ~~~ -!!! error TS2300: Duplicate identifier '1e2'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e16 = { 0x20: 0, 3.2e1: 0 }; ~~~~~ -!!! error TS2300: Duplicate identifier '3.2e1'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. var e17 = { a: 0, b: 1, a: 0 }; ~ -!!! error TS2300: Duplicate identifier 'a'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. // Accessor and property with the same name var f1 = { a: 0, get a() { return 0; } }; diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt index 397e7e134e00b..eeacad3ef0c98 100644 --- a/tests/baselines/reference/objectSpreadNegative.errors.txt +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -6,8 +6,8 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(16,5): error TS2322 tests/cases/conformance/types/spread/objectSpreadNegative.ts(23,1): error TS2741: Property 'b' is missing in type '{ s: string; }' but required in type '{ s: string; b: boolean; }'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(25,1): error TS2741: Property 's' is missing in type '{ b: boolean; }' but required in type '{ s: string; b: boolean; }'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,20): error TS2783: 'b' is specified more than once, so this usage will be overwritten. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,36): error TS2300: Duplicate identifier 'b'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,53): error TS2300: Duplicate identifier 'b'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,36): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,53): error TS1117: An object literal cannot have multiple properties with the same name. tests/cases/conformance/types/spread/objectSpreadNegative.ts(32,7): error TS2783: 'b' is specified more than once, so this usage will be overwritten. tests/cases/conformance/types/spread/objectSpreadNegative.ts(37,7): error TS2783: 'b' is specified more than once, so this usage will be overwritten. tests/cases/conformance/types/spread/objectSpreadNegative.ts(37,7): error TS2783: 'b' is specified more than once, so this usage will be overwritten. @@ -73,9 +73,9 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(74,11): error TS233 !!! error TS2783: 'b' is specified more than once, so this usage will be overwritten. !!! related TS2785 tests/cases/conformance/types/spread/objectSpreadNegative.ts:28:30: This spread always overwrites this property. ~ -!!! error TS2300: Duplicate identifier 'b'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. ~ -!!! error TS2300: Duplicate identifier 'b'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. let duplicatedSpread = { ...o, ...o } // Note: ignore changes the order that properties are printed let ignore: { a: number, b: string } = diff --git a/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt b/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt index 80931650d0a87..8eba84f03ba2a 100644 --- a/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt +++ b/tests/baselines/reference/objectTypeWithDuplicateNumericProperty.errors.txt @@ -9,9 +9,9 @@ tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts( tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(20,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(21,5): error TS2300: Duplicate identifier '1'. tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(22,5): error TS2300: Duplicate identifier '1'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(27,5): error TS2300: Duplicate identifier '1.0'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(28,5): error TS2300: Duplicate identifier '1.'. -tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(29,5): error TS2300: Duplicate identifier '1.00'. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(27,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(28,5): error TS1117: An object literal cannot have multiple properties with the same name. +tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts(29,5): error TS1117: An object literal cannot have multiple properties with the same name. ==== tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts (14 errors) ==== @@ -65,13 +65,13 @@ tests/cases/conformance/types/members/objectTypeWithDuplicateNumericProperty.ts( 1: 1, 1.0: 1, ~~~ -!!! error TS2300: Duplicate identifier '1.0'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. 1.: 1, ~~ -!!! error TS2300: Duplicate identifier '1.'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. 1.00: 1 ~~~~ -!!! error TS2300: Duplicate identifier '1.00'. +!!! error TS1117: An object literal cannot have multiple properties with the same name. } \ No newline at end of file diff --git a/tests/cases/compiler/noRepeatedPropertyNames.ts b/tests/cases/compiler/noRepeatedPropertyNames.ts new file mode 100644 index 0000000000000..cb83967d9c4af --- /dev/null +++ b/tests/cases/compiler/noRepeatedPropertyNames.ts @@ -0,0 +1,9 @@ +// @strict: false +// https://github.com/microsoft/TypeScript/issues/46815 +const first = { a: 1, a: 2 }; +class C { + m() { + const second = { a: 1, a: 2 }; + return second.a; + } +}