거꾸로 바라본 세상
[TypeScript] 인터페이스
Language/TypeScript 2023. 8. 7. 08:29

인터페이스 구문 interface Book { //?를 이용한 선택적 속성(undefined 허용) author?: string; pages: number; } const ok: Book = { author: 'Devide', pages: 365 } const missing: Book = { pages: 80 } 읽기전용 속성(readonly) readonly는 interface에서만 사용 interface Page { readonly text: string; } function read(page: Page) { console.log(page.text); //Cannot assign to 'text' because it is a read-only property. page.text = '10'; 함수와 ..