... ArdiLand Institute of Technology TypeScript – A Beginner’s Guide for Web Developers | Ardiland Institute of Technology
540-440-1540‬
USD ($)
$
United States Dollar
Br
Ethiopian Birr

TypeScript – A Beginner’s Guide for Web Developers

Created by Adugna Asrat in Quick Notes 27 Mar 2025
Share

💡 What is TypeScript?

TypeScript is a superset of JavaScript that adds static typing, making your code more reliable and easier to debug.

✅ Developed by Microsoft
✅ Compiles to plain JavaScript
✅ Works with all JavaScript frameworks (React, Angular, Vue)
✅ Used in enterprise apps and modern frontend projects


🔁 TypeScript vs JavaScript

Feature

JavaScript

TypeScript

Type Checking

None

Yes (static type checking)

IDE Autocomplete

Limited

Full, based on types

Compile-Time Errors

No

Yes

Scales for Large Projects

No

Yes


🧱 1. Type Annotations

TypeScript allows you to define what type of data a variable should hold.

let age: number = 22;

let name: string = "Maya";

let isOnline: boolean = true;

If you assign a wrong type, TypeScript will show an error before running the code.


📦 2. Arrays and Tuples

Arrays with type enforcement:

let scores: number[] = [90, 85, 78];

Tuples store fixed types and positions:

let user: [string, number] = ["Christian", 21];


📋 3. Functions with Types

Define the input and output type of a function:

function add(a: number, b: number): number {

  return a + b;

}

You can also use optional and default parameters:

function greet(name: string = "Guest"): void {

  console.log("Hello " + name);

}


🧩 4. Interfaces

Interfaces define the shape of an object. They’re like contracts.

interface Student {

  name: string;

  age: number;

  major?: string; // optional

}

let s1: Student = {

  name: "Maya",

  age: 22

};


🧱 5. Classes and OOP

TypeScript supports full object-oriented programming with classes, inheritance, and access modifiers.

class Person {

  private name: string;

  constructor(name: string) {

    this.name = name;

  }

  greet(): string {

    return "Hello, " + this.name;

  }

}

You can extend one class from another using extends.


🧰 6. Enums and Union Types

Enums are used for readable constants:

enum Role {

  Student,

  Teacher,

  Admin

}

let userRole: Role = Role.Teacher;

Union Types allow a variable to accept multiple types:

let status: string | number = "Active";

status = 1;


🧠 7. Generics

Generics make code flexible and reusable while preserving type safety.

function identity<T>(value: T): T {

  return value;

}

identity<number>(5);

identity<string>("Hello");


🧪 8. Type Inference and Type Guards

TypeScript can automatically detect the type from your code — this is called type inference.

Also, you can use conditions to guard types:

function printId(id: string | number) {

  if (typeof id === "string") {

    console.log(id.toUpperCase());

  } else {

    console.log(id.toFixed(2));

  }

}


⚙️ 9. TypeScript in Projects

✅ Works perfectly with React, Angular, Vue, Node.js
✅ Common in enterprise and startup-level web apps
✅ Use with tsconfig.json for compiler settings
✅ Easily integrate into existing JavaScript codebases


🚀 How to Start with TypeScript

  1. Install Node.js

  2. Install TypeScript using npm install -g typescript

  3. Write .ts files

  4. Compile using tsc filename.ts

  5. Link compiled .js file in HTML or run it with Node.js


💼 Careers Where TypeScript is Required

Frontend Developer (React, Angular)
Full Stack Developer (Node.js + TypeScript)
Mobile App Developer (React Native + TS)
Cloud/Serverless Dev (AWS, Firebase)
Software Engineer – Enterprise Web Apps

Comments (0)

Share

Share this post with others