Menu

What is TypeScript?

Lesson 1: What is TypeScript?

TypeScript is an open-source programming language developed by Microsoft. It is a superset of JavaScript: every valid JavaScript program is also valid TypeScript, and TypeScript adds optional static types on top.

It combines three things:

  1. A type system – describe what kind of value each variable, parameter, and return holds
  2. A compiler (**tsc**) – checks those types and outputs plain JavaScript
  3. Editor tooling – autocomplete, inline errors, and safe refactoring

The aim is not to replace JavaScript. Browsers and Node.js still run JavaScript. TypeScript helps you write it correctly.

How it compares:

Feature JavaScript TypeScript
Types Dynamic: checked at runtime Static: checked before running
Error detection When code runs While you type and at build time
Runs directly in browsers Yes No: compiled or stripped to JavaScript first
Editor autocomplete Limited guesses Accurate, based on types
Refactoring large code Risky Safer: the compiler flags every broken usage
Learning curve Lower Slightly higher

Why is it used?

Teams use TypeScript to:

  • Catch bugs early – typos, missing properties, and wrong argument types
  • Document code – types explain what a function expects without reading its body
  • Refactor safely – rename a field and see every place that must change
  • Work in large teams – shared types act as a contract between modules
  • Use modern tools – React, Next.js, Angular, Vue, NestJS, and most libraries ship TypeScript types

Examples:

  • An e-commerce team ensures every order has a total, a status, and a customer ID.
  • A banking app prevents a balance from being stored as a string.
  • A design-system team gives developers autocomplete for every component prop.

Example

In JavaScript, this bug appears only when the code runs:

function getTotal(price, quantity) {
  return price * quantity;
}

getTotal('120', 2);   // 240 (works by accident)
getTotal('₹120', 2);  // NaN at runtime

In TypeScript, the editor flags it before you run anything:

function getTotal(price: number, quantity: number): number {
  return price * quantity;
}

getTotal('₹120', 2);
// Error: Argument of type 'string' is not assignable to parameter of type 'number'.

How it works

  1. You write .ts files with type annotations.
  2. The TypeScript compiler checks that values match their types.
  3. If there are errors, you see them in the editor and terminal.
  4. The types are removed, leaving ordinary JavaScript that browsers and Node.js run.

Types exist only at development time. They add no runtime cost and do not change how your code behaves.

Common mistakes

Mistake Why it hurts Fix
Treating TypeScript as a separate language from JavaScript You relearn things you already know Think of it as JavaScript plus types
Expecting types to validate data at runtime API data can still be wrong Validate external data at runtime (Module 10)
Following very old tutorials Outdated config and defaults Use current docs; this tutorial covers TypeScript 7

Key takeaways

  • TypeScript is JavaScript with static types and a compiler that checks them.
  • Types catch mistakes before code runs and make large codebases easier to change.
  • Types disappear in the output; runtime behaviour is still JavaScript.

Try it: Take a small JavaScript function you have written before. List the types each parameter should have and what it should return.


TypeScript Tutorial

J

Jebasta





Get in Touch For Details