Intro to TypeScript
JavaScript with superpowers. Types catch bugs before your code runs.
JavaScript with superpowers. Types catch bugs before your code runs.
In 2012, Anders Hejlsberg at Microsoft had a problem. The same engineer who created C# was watching large JavaScript codebases collapse under their own weight. Bugs hid in plain sight. Refactoring was terrifying. So he built something new: a language that adds types on top of JavaScript, catching mistakes before the code ever runs.
The key insight: every valid JavaScript program is already a valid TypeScript program. You don't replace JS. You enhance it.
TypeScript is one of the fastest-growing programming languages in the world. In Stack Overflow's developer surveys, it consistently ranks among the most loved languages, ahead of JavaScript itself.
Your first TypeScript program looks almost identical to JavaScript. The only difference is a small annotation that tells the compiler what type each variable holds. Types are labels, not new syntax.
See the : string after name? That is a type annotation. It tells TypeScript (and anyone reading the code) that name will always be a string. If you accidentally try to assign a number to it later, TypeScript flags the error immediately.
TypeScript has four basic types you will use constantly: string, number, boolean, and arrays. You add them after variable names and function parameters.
Here is the key moment. What happens when you make a mistake?
TypeScript tells you about both bugs before you run the code. In plain JavaScript, these mistakes silently succeed and produce wrong results later.
Real applications pass around objects, not just strings and numbers. An interface defines the shape of an object: what properties it must have, and what type each property holds. Think of it as a blueprint.
If you misspell a property or forget a required one, TypeScript catches it instantly. The interface also serves as documentation: anyone reading the code knows exactly what a Player looks like.
Edit the field names, types, and optional markers to see the interface update in real time.
TypeScript is not just about catching typos. It fundamentally changes how you write and maintain code. Here is why professional teams choose it.
Type errors surface the moment you write them, not when a user triggers the bug in production. Entire categories of bugs simply disappear.
Types act as living documentation. When you see greet(name: string, age: number): string, you know exactly what the function expects and returns, without reading a single comment.
Your editor knows every property, method, and type in your codebase. Autocomplete becomes precise. Refactoring (like renaming a function) works across thousands of files safely.
TypeScript compiles down to regular JavaScript. It runs in every browser, on every server, on every phone. Your existing JS libraries work without changes.
You can add TypeScript to an existing JavaScript project one file at a time. Rename .js to .ts, add types where it helps, and leave the rest alone. No big rewrite needed.
In a study by Airbnb, adopting TypeScript across their codebase prevented an estimated 38% of the bugs that would have made it to production. Teams report spending significantly less time debugging and more time building features.
The MYTEK Lab terminal has TypeScript ready to go. Install the compiler, write a .ts file, and compile it to JavaScript. Here is the workflow.
The tsc command (TypeScript Compiler) reads your .ts file, checks all the types, and generates a plain .js file. If there are type errors, it tells you before producing any output.
Try introducing a type error on purpose, like passing a string to the add function. The compiler will show you exactly what went wrong and where.
You now understand how TypeScript adds a safety net to JavaScript. Types prevent bugs, serve as documentation, and power the autocomplete that professional developers rely on every day.
TypeScript catches mistakes at compile time, before your code ever runs. A misspelled property or wrong argument type is flagged instantly.
TypeScript is not a replacement for JS. It compiles down to plain JavaScript that runs everywhere: browsers, servers, phones.
Angular, VS Code, Slack, Airbnb, and Bloomberg all use TypeScript. It is the professional standard for large JavaScript projects.
You do not have to rewrite everything. Rename .js to .ts and add types incrementally. Every valid JS file is already valid TS.
Put your new knowledge into practice!