• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

Custom Repository 부분에서 에러가 납니다.

22.03.19 20:48 작성 조회수 3.7k

2

Postgres & TypeORM 연동하고 데이터베이스를 이용한 CRUD 구현 부근 진행중인데요.

일단 board.repository.ts 만들 때 EntityRepository가 deprecated라고 뜨더라고요.

일단 진행했는데 Repository 관련 에러가 뜨고 해결방법을 못찾아서 그냥 Entity자체를 Repository<Board> 식으로 감싸서 사용하는 식으로 해서 진행은 했습니다.

에러 내용은 아래처럼 뜹니다.

TypeError: Cannot set property metadata of #<Repository> which has only a getter

 

아 그리고 한가지 더 안되는 부분이 있었는데요.

this.boardRepository.findOne(id) 하는 부분이 에러가 나더라고요.

src/boards/boards.service.ts:17:54 - error TS2559: Type 'number' has no properties in common with type 'FindOneOptions<Board>'.

 

그래서 이부분은 

const found = await this.boardRepository.findOne({ where: { id } });

이렇게 작성해서 해결은 했습니다만.. 원인은 잘 모르겠네요ㅠ

 

답변 1

답변을 작성해보세요.

5

jeongbaebang_dev님의 프로필

jeongbaebang_dev

2022.03.24

https://docs.nestjs.com/techniques/database#typeorm-integration

WARNINGNote that we're using TypeORM v0.2, which isn't the latest version of TypeORM. The latter has substantial modifications and duplicate methods which are used on this page. You can read about typeorm@0.3.0 changes on their repository.

 

공식 문서에 보시면 현재 typeorm v0.2 버전을 유지하는걸로 나와있습니다.

아마도 현재 typeorm 버전이 0.2 이상 버전을 사용하셔서 deprecated 처리가 된것같습니다.

$ npm install typeorm@0.2  명령어를 통해서 공식문서에서 권장하는 버전으로 변경 부탁드립니다.

ZungTa님의 프로필

ZungTa

질문자

2022.03.25

감사합니다