본문 바로가기

Study Output for Myself/TypeScript

[TS]인터페이스(interface)

Interface

type alias처럼 타입을 보장해주는 방법.

interface User{
  name:string;
  age:number;
  hobbies:string[];
}

 

위 방법처럼 쓰인다. type alias와 차이점은 =(equal) 이 없다는 점이다.

 

interface Actor extends User{
  movies:string[]
}

 

extends 로 다른 interface를 상속받을 수도 있다.
&& | (union type) 은 사용할 수 없다.

 

interface User{
  readonly name:string;
  age:number;
  hobbies:string[];
}

 

readonly 속성을 앞에 붙이면 값을 수정할 수 없다.

'Study Output for Myself > TypeScript' 카테고리의 다른 글

[Typescript] Utility Types  (0) 2023.04.28
[TS] type narrowing, discriminated union  (0) 2023.03.28
[TS] Generic(제네릭)  (0) 2022.07.05
[TS]속성접근자  (0) 2022.07.04
[TS]타입 알리아스(type alias)  (0) 2022.07.02