TypeScript
TypeScript is a strongly-typed superset of JavaScript developed by Microsoft in 2012. It compiles to plain JavaScript.
Why TypeScript?
- Catches errors at compile time, not runtime
- Better IDE support — autocompletion, refactoring
- Makes large codebases more maintainable
- Self-documenting code through types
History
TypeScript was created by Anders Hejlsberg (also creator of C#) and released by Microsoft in 2012. It became the language of choice for Angular 2+ and is now widely used with React/React Native.
TypeScript vs JavaScript
// JavaScript
function add(a, b) {
return a + b
}
add('1', 2) // '12' — silent bug!
// TypeScript
function add(a: number, b: number): number {
return a + b
}
add('1', 2) // Error at compile time!
Key Features
- Static typing
- Interfaces
- Generics
- Enums
- Decorators
- Full ES6+ support