This site runs best with JavaScript enabled.

Type checking with JSDoc

Software Engineer, React Training, Testing JavaScript Training

Being able to catch bugs at compile time is a nice way to shorten feedback loop, thus become more productive. TypeScript provides static type checking. One way of integrating it in an app is refactoring entire app and adding type definition where those are needed. In some bigger apps this might take a noticeable effort.

Since TypeScript 2.3, an alternative solution has been developed by adding TypeScript and VS Code type checking support of JS files using JSDoc. This feature is optional and does not add any delays since nothing is transpiled.

This can be added in 2 ways:

  1. by inserting this comment at the top of .js file
1// @ts-check


  1. by adding the following setting to VS Code settings.json file - "javascript.implicitProjectConfig.checkJs": true

Check this feature in action:

Type checking in JSDoc

Here is the official documentation for JSdoc support in TypeScript.

Vadim Nicolai

Vadim Nicolai is a JavaScript software engineer.