Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 싸피
- 백준
- unionfind
- SQL
- react
- TypeScript
- 머신러닝종류
- 리액트
- queryset
- 플로이드워셜
- pwa적용하기
- Django
- 14658
- 알고리즘
- db
- 싸피10기
- QuerySetAPI
- sqld
- 싸피셜
- Javascript
- Python
- PWA
- git
- VITE
- vitepwa
- SSAFYcial
- 셀프넘버
- js
- 데코레이터
- SSAFY
Archives
- Today
- Total
Meme's IT
[TypeScript] 타입을 한 곳에 모아보자~~ 본문
배경
- 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 |