인프런 커뮤니티 질문&답변
fetchContacts()함수와 AddressBook class의 오류
작성
·
278
1
안녕하세요, 즐겁고 유익하게 강의 잘듣고있습니다.
이번 실습의 예제코드에서
'contacts' 와 'this.contacts'에 오류가 발생됩니다.
이런 오류는 어떻게 해결하나요?
return new Promise((resolve) => {
setTimeout(() => resolve(contacts), 2000);
});
'Contact[]' 형식의 인수는 'Contact | PromiseLike<Contact>' 형식의 매개 변수에 할당될 수 없습니다.
'then' 속성이 'Contact[]' 형식에 없지만 'PromiseLike<Contact>' 형식에서 필수입니다.
'then' 속성이 'Contact[]' 형식에 없지만 'PromiseLike<Contact>' 형식에서 필수입니다.
fetchData(): void {
fetchContacts().then((response) => {
this.contacts = response;
});
}
//Type 'Contact' is missing the following properties from type
'Contact[]': length, pop, push, concat, and 16 more
답변 1
0
장기효(캡틴판교)
지식공유자
안녕하세요 devzucca님, 좋은 질문 주셨네요 :) 타입이 서로 호환이 되지 않기 때문에 나타나는 에러인데요. 뒤쪽에 타입 호환 챕터 강의 들어보시고 이해 안가시면 말씀해 주세요 :) 수강해 주셔서 감사합니다!




