TypeScript Tutorial for Beginners (2026): Complete Guide with Practical Examples
TypeScript has become one of the most popular programming languages for modern web development. It is used by developers worldwide to build scalable, maintainable, and error-free applications. Popular frameworks such as Angular, React, Next.js, and Vue.js fully support TypeScript.
If you already know JavaScript, learning TypeScript is easy because it is a superset of JavaScript. It adds powerful features like static typing, interfaces, generics, and better tooling support.
In this guide, you’ll learn everything about TypeScript with practical examples.
What is TypeScript?
TypeScript is an open-source programming language developed by Microsoft. It extends JavaScript by adding static types and modern programming features.
The TypeScript compiler converts TypeScript code into standard JavaScript that runs in every browser and Node.js.
Simply put:
JavaScript + Type Safety = TypeScript
Why Use TypeScript?
Here are the biggest advantages:
- Detects errors before running code
- Improves code readability
- Better IDE support
- Excellent auto-completion
- Easier debugging
- Great for large projects
- Supports modern JavaScript features
- Makes code easier to maintain
Features of TypeScript
- Static Typing
- Object-Oriented Programming
- Interfaces
- Generics
- Enums
- Modules
- Decorators
- Type Inference
- Type Aliases
- Async/Await Support
- Optional Chaining
- Null Safety
Installing TypeScript
Install Node.js
Download and install Node.js from the official website.
Install TypeScript
npm install -g typescript
Check installation
tsc --version
Example output
Version 5.x.x
Create Your First TypeScript File
Create a file named
app.ts
Write
let message: string = "Hello TypeScript";
console.log(message);
Compile
tsc app.ts
Generated file
app.js
Run
node app.js
Output
Hello TypeScript
Variables in TypeScript
let name: string = "John";
let age: number = 25;
let isStudent: boolean = true;
Output
John
25
true
Arrays
let numbers: number[] = [10,20,30];
console.log(numbers);
Functions
function add(a:number,b:number):number{
return a+b;
}
console.log(add(10,20));
Output
30
Optional Parameters
function greet(name:string, city?:string){
if(city){
console.log(name + " from " + city);
}else{
console.log(name);
}
}
greet("Vikash");
greet("Rahul","Delhi");
Interfaces
Interfaces define object structure.
interface User{
name:string;
age:number;
}
const person:User={
name:"John",
age:28
};
console.log(person);
Classes
class Employee{
name:string;
constructor(name:string){
this.name=name;
}
display(){
console.log(this.name);
}
}
const emp=new Employee("Amit");
emp.display();
Output
Amit
Inheritance
class Animal{
speak(){
console.log("Animal Sound");
}
}
class Dog extends Animal{
bark(){
console.log("Woof");
}
}
const dog=new Dog();
dog.speak();
dog.bark();
Generics
function identity<T>(value:T):T{
return value;
}
console.log(identity<string>("Hello"));
console.log(identity<number>(100));
Enum
enum Color{
Red,
Green,
Blue
}
console.log(Color.Green);
Output
1
Union Types
let id:number|string;
id=100;
id="EMP101";
Type Alias
type UserID=string|number;
let user:UserID="ABC123";
Any Type
let value:any;
value=10;
value="Hello";
value=true;
Unknown Type
let input:unknown;
input="Hello";
Readonly Property
interface Car{
readonly model:string;
}
const car:Car={
model:"BMW"
};
Async Function
async function getData(){
return "Data Loaded";
}
getData().then(console.log);
TypeScript vs JavaScript
| Feature | TypeScript | JavaScript |
|---|---|---|
| Typing | Static | Dynamic |
| Compilation | Required | Not Required |
| Error Detection | Before Runtime | Runtime |
| IntelliSense | Excellent | Basic |
| Scalability | High | Medium |
| Maintenance | Easy | Moderate |
Real-World Applications
TypeScript is widely used for:
- Angular Applications
- React Projects
- Next.js Applications
- Node.js APIs
- Enterprise Software
- Banking Applications
- E-commerce Platforms
- Dashboard Applications
- SaaS Products
- Mobile Apps
Best Practices
- Use strict mode
- Avoid using
any - Create reusable interfaces
- Use generics whenever possible
- Keep functions small
- Use meaningful variable names
- Organize code into modules
- Enable ESLint
- Follow consistent coding standards
Common Interview Questions
Is TypeScript a programming language?
Yes.
Who developed TypeScript?
Microsoft.
Is TypeScript faster than JavaScript?
Performance is similar because TypeScript is compiled into JavaScript before execution.
Can JavaScript run TypeScript?
No. TypeScript must first be compiled into JavaScript.
Does TypeScript replace JavaScript?
No. TypeScript builds on JavaScript and compiles to it.
Conclusion
TypeScript is one of the best languages for modern web development. Its static typing, powerful tooling, and maintainability make it ideal for projects ranging from small websites to enterprise applications. Learning TypeScript alongside JavaScript can significantly improve code quality, reduce bugs, and increase developer productivity. Whether you’re building a React application, an Angular project, or a Node.js API, TypeScript is a valuable skill for every web developer.
FAQ
Is TypeScript easy to learn?
Yes. If you know JavaScript, TypeScript is straightforward to learn.
Is TypeScript free?
Yes. TypeScript is open source and free to use.
Which companies use TypeScript?
Many major companies, including Microsoft, Google, Slack, Airbnb, Asana, and Shopify, use TypeScript in their development workflows.
Can beginners learn TypeScript?
Yes. It is beginner-friendly, especially for those with basic JavaScript knowledge.