There is no dobut that TypeScript’s type checking can prevent bugs even before you run the code. It’s an amazing feature. But did you know that you can turn it on in regular .js files?

The problem

Imagine you have written code like this. At first glance you might not see any problem.

But actually localstorage should be camelCased.

Seamless solution

Just add the following at the top of the file:

// @ts-check

And it’s done! 🚀

Amazing! Isn’t it?

You can also set it up globally using below settings:

{
  "javascript.implicitProjectConfig.checkJs": true
}

resources


Karol Świeca

My thougths on JavaScript, AWS Cloud and other aspects of being Software Engineer