Typescript - interface

uphoon·2023년 2월 22일
0
post-thumbnail

오늘의 한마디

type alias와 같이 타입을 지정하는 interface에 대해 알아보고
또, 어떠한 점이 다른지 알아보자.

1. 기본사용 방법

interface Person {
	name : string,
    age : number,
}

// extends
interface Child extends Person {
	disc : string
}

interface와 type의 다른점은
바로 자바스크립트의 class처럼 extends가 가능
또 interface는 중복이 가능하다. 똑같은 이름의 인터페이스를 만들수 있다. 중복선언을 하면 자동으로 extends가 된다.

더 알아보기 )
type에서 속성합치기

type Person = { name : string }
type Child = { age : number } & Person

&기호를 사용하여 합치는 것을 intersection이라고 한다.

profile
혼자 끄적여보는 필기 저장소 | 잠깐쓰고 잊지말고 기록하는 습관.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN