TypeScript Support in Node.js with –experimental-strip-types | Node.js 202

TypeScript Support in Node.js with –experimental-strip-types | Node.js 202

How node.js support Typescript?

The Node.js project is continuously evolving to support modern JavaScript and TypeScript development practices. One of the latest advancements is the introduction of the experimental --experimental-strip-types flag, allowing developers to run TypeScript files directly in Node.js by stripping out type annotations. This feature simplifies the development workflow, making it more convenient for developers to integrate TypeScript into their Node.js projects.

You can find their roadmap for typescript support here Roadmap for experimental TypeScript support

In this tutorial we will be actually creating a demo project, So that we can sure how it's gonna work!

Demo project

I'm pretty sure that you have experience with creating node.js project.

  • Open a dir where you want keep project and run the following command.

  • npm init -y it will initialize a node.js project.

  • Create a file index.ts within same directory

See the structure of my project in the following image. I hope you have something like or it's up to you!

  • Change the package.json config.

      {
        "name": "src",
        "version": "1.0.0",
        "main": "index.ts", // here you have to set this
        "scripts": {
          "test": "echo \"Error: no test specified\" && exit 1"
        },
        "keywords": [],
        "author": "",
        "license": "ISC",
        "description": ""
      }
    

    Executing Typescript file in node.js

    You have to open your Vs code terminal with your current working directory and run the command node --experimental-strip-types .\index.ts. Now you should be able to see output like the following image.

    Also, you can read the red message that it is an experimental feature not LTS.

Did you find this article valuable?

Support Shivam Sharma by becoming a sponsor. Any amount is appreciated!