Cơ BảnTypeScript iconTypeScript

interface và type alias khác nhau như thế nào? Khi nào dùng cái nào?

  • Interface: có thể extend và merge (declaration merging), chỉ describe object shapes.
  • Type alias: linh hoạt hơn (union, intersection, primitives, tuples, conditional types), không merge.
  • Quy tắc: dùng interface cho public API và khi cần extend, dùng type cho unions/intersections và khi cần advanced type features.

Xem toàn bộ TypeScript cùng filter theo level & chủ đề con.

Mở danh sách TypeScript