Type hints for JavaScript in Visual Studio Code

Type hints for JavaScript in Visual Studio Code

You've got some javascript you want to refactor so you open Visual Studio Code and get cracking. But since you've decided to write it in plain javascript it's an untyped mess. You look at that property you just renamed, are you sure you found all instances of it? Are you sure if you just decided to Find-and-Replace that you haven't accidentally renamed something else?

If only you could make VS Code treat your javascript like typescript, just for a moment...

Simply put this at the very beginning of the file and that's exactly what VS Code will do

// @ts-check

This will probably give you a lot of false positives, global variables such as jQuery will be marked as errors as it can't find a definition but better to have to sort through some false positives and be sure that you are changing what you think you are.