배경
- consult라는 type이 상당히 긴데, 자주쓰임
- 아이고 불편해…그래서 따로 빼서 import 하려고 함
해 보 자 고
src/types/DataTypes.ts 라는 파일을 만들어 주고,
// DataTypes.ts
// 고민 타입
export type consultType = {
consultId : number,
memberId : number,
title : string,
content : string,
categoryId : number
}
이런식으로 export를 바로 하면서 넣어주자
만약 여러개가 되어도
// DataTypes.ts
// 고민 타입
export type consultType = {
consultId : number,
memberId : number,
title : string,
content : string,
categoryId : number
}
// 다른 타입
export type otherType = {
name: string
}
똑같이 해주면 됨
그러고 나서 import 해주자
import { consultType } from "../../types/DataTypes";
이렇게 한다음에 필요한 곳에 다 가져다가 붙이믄 댐
간단하고 편하구만!
'FrontEnd > TypeScript' 카테고리의 다른 글
[TypeScript] TypeScript 기본지식 (0) | 2024.06.28 |
---|---|
[TypeScript] TypeScript와 함께 비동기 처리를 해보자 (0) | 2024.03.22 |