Entity User có các field id, email, password, createdAt. Bạn muốn kiểu response giống User nhưng không có password. Cách viết nào phù hợp nhất?
Xem đáp án và giải thích
Utility type giúp suy ra kiểu mới từ kiểu có sẵn thay vì viết lại: Omit bỏ key, Pick giữ key, Partial làm optional (hay dùng cho DTO update). Lưu ý kiểu chỉ có tác dụng lúc compile: Omit không tự xoá password khỏi object thật, bạn vẫn phải map dữ liệu hoặc dùng select/@Exclude() khi trả response. Trong NestJS, @nestjs/mapped-types có OmitType, PartialType cho DTO class.