티스토리 뷰
function object({a,b}:{a:number; b:number}): string {
return `${a+b}`
}
객체로 넘겨줄때 {객체 명시} : {객체 타입 명시} : return 타입 명시
1. 비동기함수에서 사용해 보기
async funciton getPerson() {
const res = await fetch(`http://localhost.5000/people`);
if(!res.ok) {
throw new Error();
}
return res.json();
}
getPerson().then((res) => console.log(res))
아래의 객체를 받는다고 했을때
[
{id:1, age:20, height:180},
{id:2, age:28, height:170},
{id:3, age:31, height:150},
]
↓
interface Person = {
id:number;
age: number;
height: number;
}
async funciton getPerson():Promise<Person[]> {
const res = await fetch(`http://localhost.5000/people`);
if(!res.ok) {
throw new Error();
}
return res.json();
}
getPerson().then((res) => console.log(res))
으로 적용할 수 있다.
2.제네릭<T>
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
useState뒤에 따라오는 <string> 부분이 <T> 부분인데
[안에 존재하는 값들은 제네릭으로 입력된 타입으로만 받을 수 있다] 정로로만 이해를 하고 넘어가도록 하겠다..
왜냐면 아직 정확하게 뭔소린지 모르겠으므로..
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 별점만들기
- simple Icon 사용방법
- Fetch와 Axios 의 장단점
- 별점 색채우기
- nextjs 토큰 만료처리하기
- Warning: A component is changing an uncontrolled input to be controlled.
- styled component 조건부 사용방법
- Warning: Each child in a list should have a unique "key" prop.
- readme 역할
- 영화별점만들기
- readme 작성 방법
- readme 이미지 추가 방법
- git cache
- 유효성검사
- axiosinstance 사용 시 토큰 사용 법
- axios CRUD
- axios 사용하기
- readme 작성해야 하는 이유
- 에러모음집
- styled component 설치방법
- 유효성검사 css
- 영화 별점
- axios instance 작성하기
- styled component GlobalStyle 사용방법
- readme작성해보기
- axios 설치하기
- Warning: validateDOMNesting(...): <li> cannot appear as a descendant of <li>
- styled component 사용방법
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함