Skip to content

Repository files navigation

๐ŸŸฆ TypeScript โ€” Zero to Advanced

A structured hands-on journey through TypeScript fundamentals, type systems, modern patterns, and React + TypeScript development.


TypeScript React Vite Axios HTML5 CSS3 GitHub


๐Ÿ“Š Quick Repository Stats

๐Ÿ“ Learning Folders ๐Ÿ“„ Source Files โš›๏ธ React/TSX Components ๐Ÿช Custom Hooks
16 28 5 1

๐Ÿงญ Table of Contents


๐Ÿ“– About This Repository

This repository documents a practical, step-by-step learning path for TypeScript โ€” progressing systematically from core syntax annotations to advanced type constructs, asynchronous data fetching, and real-world React + TypeScript web application development.

Learn
   โ†“
Understand
   โ†“
Write TypeScript
   โ†“
Practice
   โ†“
Build with React
   โ†“
Apply Type Safety

๐Ÿ—บ๏ธ Learning Roadmap

๐ŸŸข STAGE 1 โ€” FOUNDATION
      โ””โ”€โ”€ Type Annotations โ€ข Basic Types โ€ข Type Inference โ€ข Compile-Time Checking
            โ†“
๐ŸŸก STAGE 2 โ€” CORE TYPE SYSTEM
      โ””โ”€โ”€ Union & Literal Types โ€ข Type Narrowing โ€ข Type Assertions โ€ข Type Aliases
            โ†“
๐Ÿ”ต STAGE 3 โ€” OBJECTS & FUNCTIONS
      โ””โ”€โ”€ Object Shapes โ€ข Optional/Default Params โ€ข Utility Types (Partial, Required, Readonly)
            โ†“
๐ŸŸฃ STAGE 4 โ€” DATA STRUCTURES & OOP
      โ””โ”€โ”€ Typed Arrays โ€ข Tuples โ€ข Enums (Numeric, String, Const) โ€ข Classes & OOP
            โ†“
๐ŸŸ  STAGE 5 โ€” INTERFACES & GENERICS
      โ””โ”€โ”€ Interfaces & Merging โ€ข Generic Functions & Constraints โ€ข Type Reusability
            โ†“
โšก STAGE 6 โ€” ASYNCHRONOUS TYPESCRIPT
      โ””โ”€โ”€ Typed API Integration (Axios & Native Fetch) โ€ข Promises โ€ข Error Handling
            โ†“
โš›๏ธ STAGE 7 โ€” REACT + TYPESCRIPT APPLICATION
      โ””โ”€โ”€ Typed Components โ€ข PropsWithChildren โ€ข Custom Hooks (useFetch<T>) โ€ข Form Events

๐Ÿ“š Learning Journey (Folder Breakdown)

Every directory isolates a specific stage of the TypeScript learning path with practical code examples:

๐Ÿ“… Stage ๐Ÿ“š Topic ๐Ÿ“‚ Location ๐ŸŽฏ Learning Objective
00 Compiler & Type Safety 00 Ts Folder/ Setting up TypeScript, compile-time error detection, primitive string/number checks
01 Type Annotations 1st Ts Folder/ Explicit type signatures for function parameters and return types
02 Type Inference 2nd Ts Folder/ Understanding TypeScript's automatic type inference mechanism
03 Unions & Literals 3rd Ts Folder/ Union types (string | number) and strict string literal unions
04 Type Narrowing 4th Ts Folder/ Control-flow type narrowing using typeof guards & optional parameters
05 Assertions & unknown 5th Ts Folder/ Safe type narrowing with unknown vs unsafe any and type casting
06 Type Aliases 6th Ts Folder/ Creating reusable custom object type contracts using type
07 Object Types & Shapes 7th Ts Folder/ Object literals, property type inference, and nested structure constraints
08 Functions & Utilities 8th Ts Folder/ Function return signatures (void, null), default/optional params, Partial<T>, Required<T>, Readonly<T>
09 Arrays, Tuples & Enums 9th Ts Folder/ Typed arrays (T[]), tuples ([string, number]), numeric & string enum, const enum
10 Classes & OOP 10th Ts Folder/ Class constructors, access modifiers (public, private, protected), methods & instantiation
11 Interfaces 11th Ts Folder/ Defining object contracts with interface, optional properties (?), inheritance (extends)
12 Generics 12th Ts Folder/ Reusable type-safe code using generic parameters (<T>) and constraints
13 Axios API Integration 13th Ts Folder/ Type-safe HTTP requests using Axios (axios.get<T>), async/await, error handling
14 Native Fetch API 14th Ts Folder/ Typed asynchronous API calls using native fetch(), response.ok checks, JSON parsing
15 React + TypeScript App 15th Ts Folder/ Full-fledged React + Vite SPA with typed components, props, hooks, forms, and custom state

๐Ÿง  TypeScript Concepts Covered

๐Ÿง  Concept ๐Ÿ“‚ Primary Location ๐Ÿ’ก Practical Application
Type Annotations 1st Ts Folder/ Explicitly declaring variable and parameter types
Type Inference 2nd Ts Folder/ Letting TypeScript infer variable types automatically
Union & Literal Types 3rd Ts Folder/ Restricting variables to finite sets of scalar/string literal values
Type Guards & Narrowing 4th Ts Folder/ Safely checking types at runtime using typeof conditions
unknown Top Type 5th Ts Folder/ Forcing explicit type narrowing before property access over any
Type Aliases 6th Ts Folder/ Modeling reusable domain objects (type ChaiOrder = { ... })
Function Signatures 8th Ts Folder/ Return types, optional (?) & default parameters, void logging
Utility Types 8th Ts Folder/ Standard library utilities: Partial<T>, Required<T>, Readonly<T>
Arrays & Tuples 9th Ts Folder/ Homogeneous lists (string[]), fixed-length positional tuples ([string, number])
Enums & Const Enums 9th Ts Folder/ Strongly-typed constant collections (ChaiType, const enum SugarLevel)
Classes & Access Controls 10th Ts Folder/ Object-oriented state encapsulation with public/private attributes
Interfaces 11th Ts Folder/ API contracts, optional fields, declaration merging, class implementation
Generics 12th Ts Folder/ Parameterized functions (wrapInArrays<T>(item: T): T[]) for maximum reusability
Typed Asynchronous HTTP 13th Ts Folder/ & 14th Ts Folder/ Strongly-typed API client responses using Axios (axios.get<Todo>) & fetch()

โš›๏ธ React + TypeScript Integration

Location: 15th Ts Folder/

The culmination of the learning journey integrates TypeScript into a modern Vite + React single-page application.

React Component  โ”€โ”€>  Typed Props Interface  โ”€โ”€>  Strict State Types  โ”€โ”€>  Generic Custom Hooks

๐Ÿงฉ Component Architecture

The React application demonstrates real-world component design patterns:

๐Ÿงฉ Component ๐Ÿ“‚ Location ๐ŸŽฏ Purpose & TypeScript Usage
Card Card.tsx Renders item information using an explicit CardProps interface with optional isSpecial?: boolean and default values.
CardLayout Children.tsx Demonstrates React layout wrapping using PropsWithChildren<{ title: string; footer?: ReactNode }> for container component composition.
Lists Lists.tsx Receives array props (List[]), map-renders nested Card components, and performs conditional prop computations (isSpecial={price > 30}).
OrderForm OrderForm.tsx Controlled form input with typed event handlers (React.FormEvent<HTMLFormElement>) and typed callback props (onSubmit(order: { name: string; cups: number })).
Counter counter.tsx Simple stateful component utilizing typed state hooks (useState<number>(1)).

๐Ÿช Custom Hooks

File: useFetch.ts

The application features a reusable, generic asynchronous custom hook for network requests:

interface FetchState<T> {
  data: T | null;
  loading: boolean;
  error: string | null;
}

export function useFetch<T>(url: string): FetchState<T> {
  // Generic state management for API calls
}

๐Ÿ’ก Why TypeScript Matters Here

  • ๐Ÿงฌ Generics (<T>): Allows useFetch to fetch any data payload (e.g. List[], User, Todo) while preserving end-to-end type safety.
  • ๐Ÿ›ก๏ธ Discriminated Union / State Shape: Guarantees consumers check loading and error states safely.
  • ๐Ÿ“ฆ Reusability: One hook satisfies all API endpoints without resorting to any.

๐Ÿงพ Shared Types Architecture

File: types.ts

Shared type definitions are centralized to maintain a single source of truth across components:

export interface List {
  id: number;
  name: string;
  price: number;
}

This interface is exported and imported into App.tsx and Lists.tsx, enforcing consistent data models across component boundaries.


๐Ÿ”ฌ TypeScript โ†’ React Connection

TypeScript Concept            React Application Implementation
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Interface / Type Alias  โ”€โ”€โ”€>  Component Props (CardProps, OrderFormProps)
Generics (<T>)          โ”€โ”€โ”€>  Generic Custom Hooks (useFetch<T>)
Union Types             โ”€โ”€โ”€>  Component Variants & Dynamic UI States
Optional Fields (?)     โ”€โ”€โ”€>  Optional Props with Default Fallbacks
Type Guards (typeof)    โ”€โ”€โ”€>  Event Handlers & Form Input Parsing
PropsWithChildren       โ”€โ”€โ”€>  Layout Wrappers & Slot Composition

๐Ÿ“ Repository Structure

typescript-zero-to-advanced/
โ”œโ”€โ”€ ๐ŸŸข 00 Ts Folder/                 # Basic setup & compiler error checks
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ basic.ts
โ”œโ”€โ”€ ๐Ÿ“š 1st Ts Folder/                 # Function annotations
โ”œโ”€โ”€ ๐Ÿ“š 2nd Ts Folder/                 # Type inference
โ”œโ”€โ”€ ๐Ÿ“š 3rd Ts Folder/                 # Union & literal types
โ”œโ”€โ”€ ๐Ÿ“š 4th Ts Folder/                 # Type narrowing & typeof
โ”œโ”€โ”€ ๐Ÿ“š 5th Ts Folder/                 # unknown type vs assertions
โ”œโ”€โ”€ ๐Ÿ“š 6th Ts Folder/                 # Type aliases
โ”œโ”€โ”€ ๐Ÿ“š 7th Ts Folder/                 # Object shapes & type inference
โ”œโ”€โ”€ ๐Ÿ“š 8th Ts Folder/                 # Functions & Partial/Required/Readonly
โ”œโ”€โ”€ ๐Ÿ“š 9th Ts Folder/                 # Arrays, Tuples & Enums
โ”œโ”€โ”€ ๐Ÿ“š 10th Ts Folder/                # Classes & OOP access modifiers
โ”œโ”€โ”€ ๐Ÿ“š 11th Ts Folder/                # Interfaces & merging
โ”œโ”€โ”€ ๐Ÿ“š 12th Ts Folder/                # Generics (<T>)
โ”œโ”€โ”€ โšก 13th Ts Folder/                # Axios API integration
โ”œโ”€โ”€ โšก 14th Ts Folder/                # Native fetch API integration
โ”œโ”€โ”€ โš›๏ธ 15th Ts Folder/                # React + TypeScript Application
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Components/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Card.tsx              # Typed props & defaults
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Children.tsx          # PropsWithChildren layout
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Lists.tsx             # List rendering & array props
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ OrderForm.tsx         # Typed form & event handlers
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ counter.tsx           # Typed useState hook
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Hooks/
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ useFetch.ts           # Generic custom hook <T>
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ types.ts                  # Shared app interfaces
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ App.tsx                   # Main React entry component
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ main.tsx                  # React DOM mount point
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ package.json              # App dependencies & scripts
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ vite.config.ts            # Vite configuration
โ””โ”€โ”€ ๐Ÿ“– README.md                     # Documentation

โ–ถ๏ธ Getting Started

1. Running Standalone TypeScript Files (00 to 14)

Navigate to any standalone lesson folder and compile/run with TypeScript:

# Using tsc (TypeScript Compiler) + Node
cd "00 Ts Folder"
npx tsc basic.ts
node basic.js

# Or run directly with ts-node / bun (if installed)
npx ts-node basic.ts

2. Running the React + TypeScript Application (15th Ts Folder)

Navigate into the React project directory, install dependencies, and start the Vite development server:

# Navigate to React project directory
cd "15th Ts Folder"

# Install dependencies
npm install

# Start Vite local development server
npm run dev

Then open http://localhost:5173 in your browser.


๐Ÿง  Learning Philosophy

Learn Concept  โ”€โ”€>  Write Code  โ”€โ”€>  Compile  โ”€โ”€>  Debug  โ”€โ”€>  Refactor  โ”€โ”€>  Build React App
  1. ๐Ÿ“š Learn: Understand type system mechanics and static analysis.
  2. โœ๏ธ Write: Practice syntax in isolated TypeScript files.
  3. โš™๏ธ Compile: Let the TypeScript compiler catch errors before runtime.
  4. ๐Ÿ” Debug: Inspect type errors, fix narrowing issues, and refine types.
  5. โš›๏ธ Build: Implement concepts into real-world React UIs.

๐ŸŽฏ Skills Covered

  • TypeScript Fundamentals: Primitive types, type annotations, compiler configuration
  • Type System Mechanics: Type inference, union types, literal types
  • Control-Flow Narrowing: Type guards, typeof, unknown safe assertions
  • Object & Function Modeling: Type aliases, optional parameters, function return signatures
  • Built-in Utility Types: Partial<T>, Required<T>, Readonly<T>
  • Data Structures: Typed arrays (T[]), fixed-length tuples, readonly tuples
  • Enumerations: Numeric enums, string enums, performance-focused const enum
  • Object-Oriented Programming: Classes, constructors, public/private/protected modifiers
  • Interface Design: Object shape contracts, extends inheritance, optional fields
  • Generic Programming: Reusable generic functions (<T>) and constraints
  • Asynchronous Type Safety: Typing Axios client responses & native fetch() calls
  • React Integration: Typing component props, PropsWithChildren, ReactNode
  • Event Handling: Typing form events (React.FormEvent) and input change events
  • Custom React Hooks: Designing reusable generic custom state hooks (useFetch<T>)

๐Ÿ“Š Learning Progression

TypeScript Foundation (00 - 02)
   โ†“
Unions, Narrowing & unknown (03 - 05)
   โ†“
Type Aliases & Functions (06 - 08)
   โ†“
Arrays, Tuples & Enums (09)
   โ†“
Classes & Interfaces (10 - 11)
   โ†“
Generics (<T>) (12)
   โ†“
Async API Integration (13 - 14)
   โ†“
React + TypeScript Application (15)

๐Ÿš€ What This Repository Demonstrates

  • ๐Ÿ›ก๏ธ Compile-Time Error Prevention: Eliminates undefined is not a function errors before code hits production.
  • ๐Ÿค Self-Documenting Code Contracts: Interfaces and type aliases serve as explicit documentation for API boundaries and component props.
  • ๐Ÿ”„ Confident Refactoring: Change data structures with confidence knowing compiler errors will flag every broken usage site.
  • โš›๏ธ Production-Ready React Patterns: Demonstrates type-safe component props, layout children composition, form event handling, and generic custom hooks.

๐Ÿ”ฎ Future Roadmap

Note: The following topics are planned for future learning expansion and advanced TypeScript study.

  • โฌœ Advanced Generics: Conditional types (T extends U ? X : Y), infer keyword usages
  • โฌœ Mapped & Template Literal Types: Dynamic type transformations and string template types
  • โฌœ Declaration Files (.d.ts): Authoring custom ambient type definitions for untyped packages
  • โฌœ Type-Level Programming: Utility types implementation from scratch
  • โฌœ Advanced React Patterns: Polymorphic components, useReducer with typed action unions
  • โฌœ Full-Stack TypeScript: End-to-end type safety using Node.js, Express/NestJS, and Prisma ORM

๐Ÿง‘โ€๐Ÿ’ป Author

Built and maintained with passion as part of a continuous frontend engineering and TypeScript learning journey.


โญ If you find this repository helpful for learning TypeScript, consider giving it a star! โญ

Happy Coding! ๐Ÿš€

About

My TypeScript journey from fundamentals to advanced concepts, with hands-on examples, practice, and real-world development patterns.

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Contributors

Languages