mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-08 22:29:37 -05:00
"No repeated property names" error in object literals is duplicated in strict mode (#46929)
* "No repeated property names" error in object literals is duplicated in strict mode * fix indent
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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
|
||||
~~~
|
||||
|
||||
@@ -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.
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
18
tests/baselines/reference/noRepeatedPropertyNames.errors.txt
Normal file
18
tests/baselines/reference/noRepeatedPropertyNames.errors.txt
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
23
tests/baselines/reference/noRepeatedPropertyNames.js
Normal file
23
tests/baselines/reference/noRepeatedPropertyNames.js
Normal file
@@ -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;
|
||||
}());
|
||||
25
tests/baselines/reference/noRepeatedPropertyNames.symbols
Normal file
25
tests/baselines/reference/noRepeatedPropertyNames.symbols
Normal file
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
31
tests/baselines/reference/noRepeatedPropertyNames.types
Normal file
31
tests/baselines/reference/noRepeatedPropertyNames.types
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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; } };
|
||||
|
||||
@@ -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 } =
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
9
tests/cases/compiler/noRepeatedPropertyNames.ts
Normal file
9
tests/cases/compiler/noRepeatedPropertyNames.ts
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user