Getting Started with TypeScript: A Beginner's Guide to Setting Up a Project
Learn how to set up a new TypeScript project from scratch and start coding your first TypeScript application.
Introduction to TypeScript
TypeScript is a superset of JavaScript that adds optional static typing and other features to improve the development experience. In this tutorial, we will guide you through the process of setting up a new TypeScript project.
Step 1: Install Node.js and npm
Before you can start using TypeScript, you need to have Node.js and npm installed on your computer. You can download the latest version of Node.js from the official Node.js website.
Step 2: Initialize a New Project
Create a new directory for your project and navigate to it in your terminal or command prompt. Then, run the following command to initialize a new npm project:
npm init -y
Step 3: Install TypeScript
Install TypeScript using npm by running the following command:
npm install --save-dev typescript
Step 4: Create a TypeScript Configuration File
Create a new file called tsconfig.json in the root of your project directory. This file will contain the configuration settings for the TypeScript compiler.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}
Step 5: Write Your First TypeScript Code
Create a new file called greeter.ts and add the following code:
function greet(name: string) {
console.log(`Hello, ${name}!`);
}
greet('Alice');
Step 6: Compile and Run Your Code
Compile your TypeScript code into JavaScript using the following command:
tsc greeter.ts
Then, run the compiled JavaScript code using Node.js:
node greeter.js
You should see the output Hello, Alice! in your terminal or command prompt.
Ready for more? These paid resources pick up where this lesson leaves off.
Project-based TypeScript video courses — the perfect paid next step after these free lessons.
Browse on Udemy →Hand-picked TypeScript books to master the fundamentals offline.
See on Amazon →Some links on this page are affiliate links: we may earn a commission at no extra cost to you. We only recommend tools we believe are genuinely useful.