Introduction to TypeScript
TypeScript is JavaScript with name tags.
A type is a name tag on a toy.
It tells you what kind of thing you have.
TypeScript checks those name tags before your code runs.
What is TypeScript?
TypeScript is a language built on top of JavaScript.
You write code that looks a lot like JavaScript.
Then you add tiny type labels.
A compiler is a tool that turns TypeScript into plain JavaScript.
What is a type?
A type is a name tag.
It says this box holds a string, or a number, or something else.
A string is text in quotes.
A number is a count or a size.
A tiny first example
Put : string after a name.
That tells TypeScript the box only holds text.
If you try to put a number in that box, TypeScript says no.
Types go away when the code runs
TypeScript does not change how JavaScript runs.
After you compile, the type labels disappear.
Your program is still just JavaScript.
Browsers and Node run that JavaScript like always.
Why learn it now?
Types catch many mistakes early.
Your editor can help you finish words.
That help is called autocomplete.
Autocomplete means the editor suggests the next word.
Think of TypeScript as JavaScript with a friend who checks name tags before playtime.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.