DEV Community 👩‍💻👨‍💻

Functional Javascript
Functional Javascript

Posted on • Updated on

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

Today's Developer Experience (DX) Tip:

install Typescript globally on your devbox

npm i -g typescript

install these in your package.json as devDependencies

npm i -D eslint eslint-plugin-jsdoc

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

tsc --init

("tsc" stands for TypeScript Compiler)

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)

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


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...

Top comments (0)

5 Website To Learn Frontend Web Development Faster

In this article, Bentil Shadrack has curated 5 resourceful sites that will help you better you web development skills really fast.