TypeScript Tutorial

TypeScript โปรเจกต์: React แอปเล็ก

โปรเจกต์สุดท้าย React แอปเล็กด้วย Vite typed props hooks useReducer ที่ type-safe ด้วย discriminated union Context ที่ typed fetch data ผ่าน zod validation และ custom hook รวมทุกอย่างจากทั้งซีรีส์เข้าเป็นแอปที่ทำงานได้จริง Read more »
TypeScript Tutorial

TypeScript โปรเจกต์: form validation library

โปรเจกต์สร้าง validation library แบบจิ๋ว schema builder ที่ประกอบ validator ได้ Infer type จาก schema ด้วย conditional type ผลลัพธ์เป็น type ที่ตรงกับ schema เป๊ะ และ error type ที่บอก field ที่ผิด เข้าใจว่า zod ทำงานยังไงเบื้องหลัง Read more »
TypeScript Tutorial

TypeScript โปรเจกต์: finite state machine ที่ type-safe

โปรเจกต์ finite state machine ที่ type-safe state และ event เป็น discriminated union transition function ที่ compiler บังคับว่าจาก state นี้ทำ event นี้ได้หรือไม่ได้ ผลลัพธ์คือ state ที่ถูกต้องเสมอ และ event ที่ไม่ valid จับได้ตอน compile Read more »
TypeScript Tutorial

TypeScript โปรเจกต์: REST API

โปรเจกต์ REST API สมุดโน้ต ครบวงจร Express กับ TypeScript better-sqlite3 zod validation ทุก request body typed handler error middleware ที่แปลง domain error เป็น HTTP status async handler wrapper และ Vitest ทดสอบด้วย supertest รวมทุกอย่างจากทั้งซีรีส์ Read more »
TypeScript Tutorial

TypeScript โปรเจกต์: typed API client

โปรเจกต์สร้าง typed API client wrapper รอบ fetch ที่รับ zod schema แล้ว validate response พร้อม infer type generic method get post put delete error type ที่แยกชัดระหว่าง network validation และ HTTP error รวม generics... Read more »
TypeScript Tutorial

TypeScript โปรเจกต์: to-do CLI

โปรเจกต์แรก to-do CLI ด้วย TypeScript และ Node commander จัดการ subcommand เก็บ task เป็นไฟล์ JSON โหลดกลับด้วย zod validate เพื่อกัน format เสีย typed Task struct และ exit code รวม Node types zod file IO... Read more »
TypeScript Tutorial

TypeScript แชร์ type ระหว่าง client กับ server

end-to-end type safety คือ type เดียวใช้ทั้ง client และ server แชร์ผ่าน package ใน monorepo แชร์ผ่าน zod schema ที่ทั้งสองฝั่ง import tRPC ให้ client รู้ type ของ API โดยตรงไม่ต้องเขียน type ซ้ำ และ OpenAPI generate type... Read more »
TypeScript Tutorial

TypeScript กับ Express

Express กับ TypeScript ต้องลง at-types slash express typing route handler ด้วย Request และ Response Request เป็น generic ที่ระบุ type ของ params body query ได้ middleware มี type และการเพิ่ม property ให้ Request อย่าง... Read more »
TypeScript Tutorial

TypeScript กับ React

typing React component ด้วย props type useState infer type จาก initial value หรือระบุ generic useRef ต้องเลือกว่าเป็น DOM ref หรือ mutable value useReducer typed ด้วย discriminated union event handler มี type ตาม element... Read more »
TypeScript Tutorial

TypeScript generics และ type ขั้นสูง

template literal types สร้าง string type จาก pattern เช่น get dollar sign key const type parameter ใน TypeScript 5.0 ทำให้ generic infer เป็น literal โดยไม่ต้อง as const recursive type สำหรับโครงสร้างซ้อน และ NoInfer... Read more »