Getting Started with TypeScript Basics
Learn the fundamentals of TypeScript and how to set up your first project.
Introduction to TypeScript
TypeScript is a superset of JavaScript that adds optional static typing and other features to improve the development experience. It's designed to help you catch errors early and improve code maintainability, thus making it a popular choice among developers.
Setting Up Your First Project
To get started with TypeScript, you'll need to have Node.js installed on your computer. Once you have Node.js installed, you can install TypeScript using npm by running the following command in your terminal:
npm install -g typescript
Basic TypeScript Syntax
TypeScript's syntax is similar to JavaScript's. Here's an example of a simple TypeScript function:
function greet(name: string) {
console.log(`Hello, ${name}!`);
}
// Call the function
console.log(greet('Alice'));
Using TypeScript with JavaScript Files
You can also use TypeScript to type-check your existing JavaScript files. To do this, you'll need to rename your JavaScript files to have a .ts extension and then run the TypeScript compiler on them.
tsc yourfile.ts
This will generate a yourfile.js file that you can use in your project.
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.