Introduction

Now this post is not intended to persuade you to begin type checking your JavaScript. Rather if you’re interested in type checking but don’t want to transform your code to typescript yet, this article will inform you how to do it.
A key benefit of this approach is that you can add type checking gradually, per file.

Enable JavaScript type checking

Install typescript

npm install -g typescript

  • Visual Studio Code can do the checks without needing to install typescript separately.
  • On other editors, you may need to configure the Typescript language server to include js files.
  • Otherwise, use the tsc cli: tsc filename.js …

In case you are trying to use parcel bundler or any code transformer using the Visual Studio Code (vscode) Chrome Debugger and get

Breakpoint ignored because generated code not found (source map problem?).

You’ll have to make sure that your generated source map points to the correct file paths.

In your launch.js

  • Use webRoot to specify your source folder
  • Override the source map location on disk with sourceMapPathOverrides

.vscode/launch.js

More info on sourceMapPathOverrides

Breakpoints may still not trigger on initial load. When you start the debugger which launches Chrome, there is a lag before vscode can attach to Chrome…

Ananto Ghosh

Everyday Coder. @anantoghosh https://mein.in

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store