TypeScript is a programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, which means every valid JavaScript code is also valid TypeScript code, but TypeScript adds additional features.

💡 Core Idea
TypeScript enhances JavaScript by adding static types, enabling developers to catch errors during development rather than at runtime.
In plain terms, TypeScript helps you write safer and more maintainable code by introducing a type system and other modern programming features.
| Aspect | JavaScript | TypeScript |
|---|---|---|
| Typing | Dynamically typed | Statically typed (optional) |
| Compilation | Interpreted by browsers | Compiled to JavaScript before running |
| Tooling | Basic error detection | Advanced error detection & IDE support |
| Learning Curve | Lower | Requires learning types & compilation |
| Use Cases | Web apps, scripts | Large-scale apps, enterprise projects |
TypeScript files use the .ts extension and need to be transpiled (converted) to plain JavaScript before they can run in browsers or JavaScript environments.
💡 Why Use TypeScript?
- Catch common errors early through static type checking.
- Improve code readability and maintainability by explicitly defining data shapes.
- Enjoy better tooling support like autocompletion, refactoring, and navigation.
- Easier collaboration in large teams and complex projects.
📌 Deep Dive: Simple TypeScript Example
function greet(name: string) {
return "Hello, " + name.toUpperCase();
}
// This will cause a compile-time error
// greet(42);
console.log(greet("Alice"));
In this example, name must be a string. If you try to call greet with a different type like a number, TypeScript will flag an error before running the code.
⚠️ Important
TypeScript only checks types during development and compilation. Once compiled, the output is plain JavaScript, which does not enforce types at runtime.
In summary, TypeScript is a powerful tool that builds on JavaScript by adding static typing and other features to improve developer experience and code quality.
Quick Knowledge Check
Test what you just learned
Question 1 of 2
What is one key feature that TypeScript adds to JavaScript?
Question 2 of 2
What file extension is typically used for TypeScript files?
Loading results...