Careeroza
TypeScript Study Material
What is TypeScript
What is TypeScript?
TypeScript is JavaScript with types. It was created by Microsoft (lead designer Anders Hejlsberg, who also designed C#) and released in 2012. Every valid JavaScript program is also a TypeScript program, but TypeScript lets you describe what kind of value each variable, parameter and object holds.
- Superset of JavaScript: you can rename a
.jsfile to.tsand start adding types slowly. - Static type checking: mistakes are found while you type, before the code runs.
- Compiles to plain JavaScript: browsers and Node.js run the JavaScript output, not TypeScript.
- Great editor support: autocomplete, rename, go to definition and inline errors in VS Code.
Your First Look at TypeScript
Example
The : string and : number parts are type annotations. Everything else is normal JavaScript.
const name: string = "Careeroza";
const year: number = 2026;
function greet(person: string): string {
return "Hello, " + person + "!";
}
console.log(greet(name));
console.log("Learning TypeScript in", year);Output
Hello, Careeroza! Learning TypeScript in 2026
What TypeScript Catches
Example
Here we pass a number where a string is expected. JavaScript would happily run this. TypeScript stops it with error TS2345 before the code ever runs.
function greet(person: string): string {
return "Hello, " + person.toUpperCase();
}
console.log(greet(42));Compiler output (tsc)
Line 5: error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
Note: Types exist only at compile time. After compiling, all annotations are removed and normal JavaScript runs.