DEV Community

Functional Javascript
Functional Javascript

Posted on • Edited on

3 2

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

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more