How to Install Typescript in My Project in 2025?


TypeScript has become an essential tool for web developers, providing a layer of type safety over JavaScript and improving both large-scale and small-scale application development. If you’re looking to harness the power of TypeScript in your projects in 2025, this guide will walk you through the steps to install it seamlessly.

Why Use TypeScript?

Before diving into the installation process, it’s important to understand why developers continue to choose TypeScript:

  • Static Typing: Helps catch errors during compile time instead of runtime, improving code quality and maintainability.
  • Enhanced Tooling: Integrates with IDEs to offer better code completion, navigation, and refactoring capabilities.
  • Future-Proof: As JavaScript evolves, TypeScript continues to match and exceed its capabilities, making it a wise long-term choice.

Step-by-Step Guide to Install TypeScript

Step 1: Set Up Node.js and npm

TypeScript is a powerful language that extends JavaScript by adding types. It’s developed and maintained by Microsoft, and in 2025, it’s more popular than ever. Before you can install TypeScript, ensure you have Node.js and npm (Node Package Manager) installed:

  1. Visit the Node.js official website to download and install the latest version of Node.js. This will also include npm by default.

  2. Verify the installation by running the following commands in your terminal:

    node -v
    npm -v

Step 2: Initialize Your Project

If you don’t have an existing project, create a new directory for it and navigate into the directory:

mkdir my-typescript-project
cd my-typescript-project

Initialize a new npm project:

npm init -y

This command will create a package.json file with default settings. You can customize this later as needed.

Step 3: Install TypeScript

Install TypeScript as a development dependency in your project:

npm install typescript --save-dev

To check if TypeScript installed correctly, you can verify the version:

npx tsc -v

Step 4: Configure TypeScript with a tsconfig.json

Create a tsconfig.json file to configure your TypeScript options. This file lives at the root of your project directory:

npx tsc --init

This command generates a tsconfig.json file with default settings. You can modify this file to suit your project needs. Key options include:

  • “target”: Specifies the JavaScript version output; ES2020 is a popular choice.
  • “module”: Determines the module code generation; commonjs is widely used for Node.js projects.
  • “strict”: Enables all strict type-checking options.

Step 5: Write TypeScript Code

Create a new TypeScript file within your project and start coding:

mkdir src
touch src/index.ts

Open src/index.ts and begin writing your TypeScript code. Here’s a simple example:

function greet(name: string): string {
  return `Hello, ${name}!`;
}

console.log(greet("World"));

Step 6: Compile TypeScript to JavaScript

Compile your TypeScript code to JavaScript using the TypeScript compiler:

npx tsc

This command will generate JavaScript files in the output directory defined in your tsconfig.json (usually dist or the same directory as your TypeScript files).

Explore More TypeScript Topics

Want to deepen your TypeScript knowledge? Check out these resources:

By following this guide, you’re well on your way to leveraging TypeScript in your 2025 projects. Happy coding!