FrontEnd/TypeScript

커스텀 type 만들기

Dean83 2024. 10. 18. 13:48

정해진 type 외에 커스텀한 형태로 만들 수 있다. 

interface, class 와 비슷하게 구성 할 수 있다.

 

export type testtype = {
	numval : number,
    ......

}


/////// 사용처에서

import {testtype} from ....

...
const val1 : testtype = {
	numval : 10,
	....
}
  • 상속
    • interface 나 class 는 extends 를 통해 상속을 할 수 있고, type 같은 경우는 & 기호를 사용한다. 
export type TypeTest1 =
{
	val1 : string,
    ....
}

export type TypeTest2 = TypeTest1 &
{
	additional : string,
    ....
}

 

'FrontEnd > TypeScript' 카테고리의 다른 글

Omit, Pick  (0) 2024.10.18
nodemon 설치 (typescript 자동 빌드) 및 기타 모듈  (0) 2024.10.18
유틸리티 타입  (0) 2024.10.17
외부모듈 사용하기  (0) 2024.10.17
type 종류  (0) 2024.10.17