interface và type alias khác nhau như thế nào? Khi nào dùng cái nào?
VI- 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.
EN- Interface: can be extended and merged (declaration merging), only describes object shapes.
- Type alias: more flexible (unions, intersections, primitives, tuples, conditional types), does not merge.
- Rule of thumb: use interface for public APIs and when extension is needed, use type for unions/intersections and advanced type features.