Kalpesh Gupta
TypeScript: An Overview
Introduction
TypeScript is a strongly typed, object-oriented, compiled superset of JavaScript developed and
maintained by Microsoft. It adds optional static typing to the language, making it easier to catch errors
during development and improve overall code quality.
1. What is TypeScript?
• A superset of JavaScript.
• Transpiles to plain JavaScript.
• Adds static type definitions to JavaScript.
• Supports modern JavaScript features (ES6+).
2. Key Features
• Static Typing: Detects type errors during compilation.
• Type Inference: Automatically infers variable types.
• Interfaces: Describes object shapes and contracts.
• Classes & Inheritance: Based on ES6 with added features.
• Access Modifiers: public , private , protected .
• Enums: Defines named constant values.
• Generics: Builds reusable components.
• Namespaces & Modules: Organize code effectively.
3. Type Annotations
let name: string = "John";
let age: number = 25;
let isStudent: boolean = true;
4. Interfaces and Types
interface Person {
name: string;
age: number;
}
function greet(person: Person) {
1
console.log(`Hello, ${person.name}`);
}
5. Classes and Inheritance
class Animal {
constructor(public name: string) {}
move(distance: number) {
console.log(`${this.name} moved ${distance} meters.`);
}
}
class Dog extends Animal {
bark() {
console.log("Woof! Woof!");
}
}
6. Generics
function identity<T>(arg: T): T {
return arg;
}
let output = identity<string>("Hello");
7. TypeScript vs JavaScript
Feature JavaScript TypeScript
Static Typing No Yes
Compile-time Checking No Yes
Interfaces No Yes
Generics No Yes
Community Support High Growing
8. Benefits of TypeScript
• Detects errors at compile time
• Improved code readability and maintainability
• Scalable for large projects
2
• Better tooling support (e.g., IntelliSense)
9. TypeScript with React and Node.js
• Easily integrates with React using .tsx files
• Strong typing for props and state in components
• Works well with Node.js for building server-side apps
10. Real-World Use Cases
• Large enterprise applications
• Applications with complex data models
• Team-based development requiring strong contracts
• Codebases needing long-term maintenance
Conclusion
TypeScript enhances JavaScript by adding static types, improving tooling, and enabling developers to
write safer and more maintainable code. It has become a standard choice for professional development
in both frontend and backend projects.