vscode, javascript: How to get warnings when I have duplicate variables in object

Viewed 797

For example, a have an object:

let obj = { prop: test, prop: test1, };

And I want to get warning on a second "prop".

2 Answers

By default, VS Code's JavaScript support only checks the syntax code. You can opt into semantic checking as well by adding a // @ts-check comment to the top of your file:

TS check reporting duplicate keys

TS check can catch many more errors than just duplicated keys. More info about ts-check

If you use ESLint and make sure the no-dupe-keys rule is enabled, it'll show a warning when you have code like that.

ESLint can be integrated into VSCode with this extension.

Related