Computed properties no throws if there is a duplicate
See original GitHub issueTypeScript Version: 3.0.0-dev.20180712
Search Terms:
Code
const A = 'a';
const x = {[A]: 1, [A]: 'b'} // x is {[A]: string}
Expected behavior: Duplicate declaration error
Actual behavior: No error
Playground Link: https://www.typescriptlang.org/play/#src=const A %3D ‘a’%3B const x %3D {[A]%3A 1%2C [A]%3A 1}
Related Issues:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:17
- Comments:7 (1 by maintainers)
Top Results From Across the Web
What's the purpose of allowing duplicate property names?
In ECMAScript 5 strict mode code, duplicate property names were considered a SyntaxError. With the introduction of computed property names ...
Read more >Object initializer - JavaScript - MDN Web Docs - Mozilla
In ECMAScript 5 strict mode code, duplicate property names were considered a SyntaxError . With the introduction of computed property names ...
Read more >Computed properties in Swift: A basic feature for safer and ...
In a real app, it's unlikely that that will happen in a single place. That duplicates code, which makes it likelier to make...
Read more >Computed Properties and Entity Framework - Dave Glick
The AccountValue property in the first example above will throw a null reference until Holdings has been initialized. If you are only using ......
Read more >Duplicate property names (was Re: @@new) - ES Discuss
... the constraint that duplicate dynamic object properties throw (in strict mode) ... both computed and static properties no longer have any duplicate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I explored the various cases where this occurs. I’ve recorded the actual errors received in each case. This was in VSCode, with TypeScript 4.4.2.
It would be ideal if all of the above cases gave the same errors, rather than mixing and matching the four different errors across the different cases.
My personal preference would be for three errors in every case:
In addition to the bug where some duplicated property names show no error at all, I believe that the following cases are also bugs: