Trung BìnhTypeScript iconTypeScript

const assertion (as const) là gì?

as const biến values thành readonly literal types cụ thể nhất. Array thành readonly tuple, object properties thành readonly literal types.

Ví dụ: const dirs = ['left', 'right'] as const tạo type readonly ['left', 'right'] thay string[]. Hữu ích để tạo strongly-typed constants.

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

Mở danh sách TypeScript