Readonly modifier của interface
Trong interface của TypeScript, có thể định nghĩa field chỉ đọc bằng cách thêm readonly modifier cho field.
tsinterfaceSomeInterface {readonlyfield : number;}
tsinterfaceSomeInterface {readonlyfield : number;}
Thông tin liên quan
📄️ Readonly modifier trong class
Trong TypeScript, thêm readonly modifier cho field để biến field đó thành chỉ đọc.
📄️ Readonly property của object type
Trong TypeScript, có thể đặt property của object thành read-only. Thêm modifier readonly vào property muốn đặt thành read-only. Khi cố gán giá trị cho property read-only, TypeScript compiler sẽ cảnh báo không thể gán.