인프런 커뮤니티 질문&답변
작성자 없음
작성자 정보가 삭제된 글입니다.
cat repository에서의 오류
작성
·
562
0
async existsByEmail(email: string): Promise<boolean> {
try {
const result = await this.catModel.exists({ email });
return result;
} catch (error) {
throw new HttpException('db error', 400);
}
}
에서 return result부분에서 오류가 발생합니다.
src/cats/cats.repository.ts:20:7 - error TS2322: Type 'Pick<Document<Cat, any, any>, "_id">' is not assignable to type 'boolean'.
20 return result;
         ~~~~~~~~~~~~~~
exists() 따라가 보면 리턴타입이 boolean이 아닌거 같은데 어떤 부분을 확인해 보면 좋을까요?
console.log로 result를 찍어보면 { _id: new ObjectId~~~} 가 나옵니다.
답변 1
3
exist() 가 버전업 되면서 {_id:...} 혹은 null을 리턴합니다. if(result) {return true} else {return false}로 바꿔주시면 됩니다.





.png?w=112)
