Trung cấp16 bài học

TypeScript Chuyên Sâu

Khóa học TypeScript nâng cao dành cho dev trung cấp — Generics, Conditional Types, Mapped Types, Narrowing, Discriminated Unions, và thiết kế type-safe library.

Bắt đầu học →
typescripttype-systemgenericsadvanced

Nội dung khóa học

Module 1 — Type System Foundations

  1. 01
    Generics nâng cao trong TypeScript
    Hiểu sâu về Generics: constraints, default types, inference, và cách dùng generics để viết code type-safe thực sự.
  2. 02
    Conditional Types trong TypeScript
    Viết kiểu 'if/else' ngay trong type system: conditional types, infer, distributive types, và các pattern thực tế.

Module 2 — Type-Level Programming

  1. 03
    Mapped Types
    { [K in keyof T]: ... } — biến đổi kiểu hàng loạt, tự viết Partial, Required, Pick, Readonly.
  2. 04
    Template Literal Types
    Ghép chuỗi ở type level: Uppercase, Capitalize, sinh type cho event name và route path.

Module 3 — Narrowing & Control Flow

  1. 05
    Type Guards & Narrowing
    typeof, instanceof, in, user-defined type guard (x is T), assertion functions — cách narrow type an toàn.
  2. 06
    Discriminated Unions
    Tagged union, exhaustiveness check với never, pattern cho state machine và API response.

Module 4 — Type Safety Patterns

  1. 07
    Branded / Nominal Types
    Chống 'primitive obsession': UserId vs string, branding technique, cách TS xử lý structural typing.
  2. 08
    Recursive Types
    Type đệ quy: JSON type, deep readonly, giới hạn depth của compiler, và khi nào nên dừng.

Module 5 — TypeScript trong thực chiến

  1. 09
    tsconfig sâu
    strict family, moduleResolution, paths, target/lib — cấu hình production thật.
  2. 10
    Declaration Files (.d.ts)
    Viết type cho JS thư viện, declare module, ambient types, @types.

Module 6 — Generics ứng dụng cao

  1. 11
    Function Overloads & Generic Inference
    Overload signatures, thứ tự inference, khi nào overload thắng generic.
  2. 12
    Builder Pattern type-safe
    Fluent API giữ type qua từng .method(), ví dụ query builder mini.

Module 7 — Hệ sinh thái & công cụ

  1. 13
    Utility Types toàn tập
    Điểm qua + tự reimplement các utility types, khi nào dùng cái nào.
  2. 14
    Type-safe với thư viện thật
    Zod (validation → type inference), React props nâng cao, generic components.

Module 8 — Capstone Project

  1. 15
    Thiết kế thư viện type-safe (phần 1)
    Dựng một validation library mini kiểu Zod thu nhỏ từ đầu.
  2. 16
    Thiết kế thư viện type-safe (phần 2)
    Hoàn thiện inference, object/array schemas, publish, viết test, đóng gói khóa học.