DEV Community

Cover image for Creating a TypeScript tsconfig for nodejs
Ben Force
Ben Force

Posted on • Originally published at justwriteapps.com

3 3

Creating a TypeScript tsconfig for nodejs

Do you hate dealing with tsconfig files? My problem is that I just don't spend enough time with them to learn all the settings. I create the config once for a new project, usually leaving most things as default, then never touch it again.

Fortunately, I recently discovered that Microsoft has created a collection of platform-specific presets to base your tsconfig on. The preset is installed as an npm package and referenced using the extends property in your tsconfig.

To setup a typescript project for node 14 install the @tsconfig/node14 preset.

npm install --save-dev @tsconfig/node14
Enter fullscreen mode Exit fullscreen mode

Now your tsconfig can be as simple as one property, but any settings in your tsconfig will override the preset values.

{
  "extends": "@tsconfig/node14/tsconfig.json"
}
Enter fullscreen mode Exit fullscreen mode

The power behind the extends property is that you can easily get started on a project with optimized settings, and if you have multiple TypeScript projects you can create your own tsconfig preset!

References

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I normally have to consult node.green

Collapse
 
thebenforce profile image
Ben Force

Hopefully this can save you some time then :)

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay