TypeScript

  1. 왜 타입스크랩트를 써야하나.
  2. TypeScipt 기초
  3. 함수 타입을 정의하자
  4. interface를 활용하자
  5. 타입 별칭이란?
  6. 연산자를 이용한 타입 정의 - 유니온 타입
  7. enum
  8. class
  9. generic
  10. promise Types
  11. todolist 만들어보기
  12. 디버깅

목차

Promise Types

// 비동기 코드,

function asyncFetchItems() {
  let items = ["a", "b", "c"];
  return new Promise(function (resolve) {
    resolve(items);
  });
}

스크린샷 2022-04-27 15.42.12.png

fetchContacts().then((response) => {
      this.contacts = response;
    });
function fetchContacts(): Promise<Contact[]> {
	const contacts: Contact[] = [...]
		return new Promise((resolve) => {
    setTimeout(() => resolve(contacts), 2000);
  });
}

fetchContacts().then((response) => {
      this.contacts = response;
    });

🔗 Reference