loading...

Quick Tip: Setup Typescript type-checking with your Pure Javascript

functional_js profile image Functional Javascript Updated on ・1 min read

Today's Developer Experience (DX) Tip:

a.
install Typescript globally on your devbox

npm i -g typescript

b.
install these in your package.json as devDependencies

npm i -D eslint eslint-plugin-jsdoc

c.
create a tsconfig.json file in the root of your project or monorepo

cd MYROOTPROJ
tsc --init

("tsc" stands for TypeScript Compiler)

d.
Open the newly generated tsconfig.json and UNCOMMENT these two lines...

  "allowJs": true,  // allow javascript files to be compiled
  "checkJs": true, // report errors in .js files

(By doing this you'll never need to use... // @ts-check)

e.
Type your function definitions with JSDoc syntax.
Make sure the top comment line starts with: /**

Summary

Now you have all the Typescript services, while keeping your code pure JavaScript.
The best of both worlds.

Example (see the squigglies):
Alt Text

Next Tip

How to register your own custom JSDoc tags in your project. Go here...
https://dev.to/functional_js/add-jsdoc-to-your-javascript-code-2lb0

Posted on by:

functional_js profile

Functional Javascript

@functional_js

Full Stack System Designer and Software Engineer

Discussion

pic
Editor guide