In fact, the first error is better, but isn't used for first;
Expected: On firsts a: 2, the error should be "An object literal cannot have multiple properties with the same name."
Actual: Duplicate identifier 'a'.
This inconsistency arose because Typescript originally targetted ES3 and ES5; duplicate property names are only an error in ES5's strict mode. In fact, they're not even an error in ES2015+'s strict mode. But this is a good error, and it should apply everywhere.
Expected: The error should be "An object literal cannot have multiple properties with the same name."
Actual: "An object literal cannot have multiple properties with the same name in strict mode."
In strict mode (
strict: true, inside a class or inside a module), duplicated property names get two errors instead of one:Expected: one error on each
a: 2.Actual: two errors on the
a: 2inside the class:In fact, the first error is better, but isn't used for
first;Expected: On
firstsa: 2, the error should be "An object literal cannot have multiple properties with the same name."Actual: Duplicate identifier 'a'.
This inconsistency arose because Typescript originally targetted ES3 and ES5; duplicate property names are only an error in ES5's strict mode. In fact, they're not even an error in ES2015+'s strict mode. But this is a good error, and it should apply everywhere.
Expected: The error should be "An object literal cannot have multiple properties with the same name."
Actual: "An object literal cannot have multiple properties with the same name in strict mode."
Thanks to https://stackoverflow.com/questions/36321790/js-two-or-more-object-properties-with-the-same-name-in-non-strict-mode for pointing out the spec changes.
The text was updated successfully, but these errors were encountered: