Reputation: 341
Since JSON.Stringify isn't valid JS it would nice to have VScode to show error or perhaps correct automatically it into JSON.stringify.
Question is that why doesn't it do it already? And how to make it happen? I believe there could be a lot of similar cases.
Upvotes: 1
Views: 1573
Reputation: 65213
Try enabling TypeScript's semantic checking in your javascript file. The easiest way to do this is by adding // @ts-check
to the top of your js file:
// @ts-check
JSON.Stringify([])
You can also enable type checking in your entire project by setting:
"javascript.implicitProjectConfig.checkJs": true
in your VSCode settings
Here's the full documentation on ts-check: https://code.visualstudio.com/docs/languages/javascript#_type-checking-and-quick-fixes-for-javascript-files
Upvotes: 3