How to Setup a TypeScript Project?
Last Updated : 25 Feb, 2025
In the world of modern web development, TypeScript has emerged as a powerful superset of JavaScript, offering static typing and improved tooling. Its strong typing system helps developers catch errors early during development, leading to more maintainable and scalable code. Whether you're starting a new project or integrating TypeScript into an existing JavaScript codebase, setting up a TypeScript project correctly from the start is crucial for long-term success.
In this article, we'll walk you through the entire process of setting up a TypeScript project. By the end of this article, you'll have a fully functional TypeScript project that is ready to be developed and scaled.
Prerequisites
Steps to Setup TypeScript Project
Step 1: Installing NodeJs and Npm
Before you can begin using TypeScript, you'll need to make sure that Node.js and npm (Node Package Manager) are installed on your system. These tools are essential for managing your project’s dependencies.
Checkout the tutorial - How to install Nodejs and npm
Step 2: Initializing your project
Open your terminal, navigate to your project directory, and run npm init -y to create a package.json file with default settings.
npm init -y
Step 3: Installing Typescript
Run npm install typescript --save-dev to add TypeScript as a development dependency to your project.
npm install typescript --save-dev
Step 4: Configuring Typescript
Execute npx tsc --init to generate a tsconfig.json file, which contains TypeScript compiler options and configurations.
npx tsc --init
package.json:
"devDependencies": { "typescript": "^5.4.5" }
Project Structure:
Step 5: Creating Your First TypeScript File
Create index.ts file which will contain the sample TypeScript code.
Example: In this example, we define a constant variable greeting with the type string and assign it the value "Hello, GeeksforGeeks!". The console.log(greeting) statement then outputs this greeting message to the console. This simple application demonstrates basic TypeScript syntax, including type annotations and basic console logging.
JavaScript // index.ts const greeting: string = "Hello, GeeksforGeeks!"; console.log(greeting);
Step to Run Application: Run the application using the following commands from the root directory of the project
npx tsc node index.js
Output:
OutputNow that your TypeScript project is set up, it’s time to bring your skills to life! Explore our Top 15 TypeScript Projects and build exciting apps like password generators, drag-and-drop lists, and more.
Similar Reads
How to Set Up a Vite Project? Vite is a modern front-end build tool that offers a fast development experience by using native ES modules in the browser. It provides a lean and efficient setup for building JavaScript applications with a focus on performance and simplicity. PrerequisitesNodejsReactJavaScript Approach We have discu
2 min read
How to add TypeScript in Next.js ? In this article, we will learn how to add TypeScript in Next.js.Why should we use TypeScript in our project? The fundamental concept of TypeScript is that it is type-strict, which means that each entity, be it a variable, a function, or an object has a definite data type. It allows minimum bugs in t
5 min read
How to Test TypeScript with Jest? Jest, a powerful JavaScript testing framework, seamlessly integrates with TypeScript, providing all the tools needed to write and run tests for your TypeScript code, ensuring quality and reliability. It handles TypeScript compilation automatically, offers features like mocking and code coverage, and
3 min read
How to import a module in Typescript ? Before starting with importing modules, first of all, we need to know the basics of modules in TypeScript. We know that JavaScript has come with the concept of modules from the ES6 version in 2015 and by 2020 had broad support in most web browsers and JavaScript runtimes. TypeScript also shares the
5 min read
Top 15 TypeScript Projects With Source Code TypeScript is a powerful, statically typed superset of JavaScript that enhances code quality and maintainability, making it a popular choice for modern web development. From building scalable applications to creating robust front-end and back-end systems, TypeScript brings structure and reliability
6 min read