Skip to content

Conversation

@soohwanpak
Copy link
Collaborator

@soohwanpak soohwanpak commented Feb 9, 2025

요구사항

기본

  • Github에 위클리 미션 PR을 만들어 주세요.
  • React 및 Express를 사용해 진행합니다.
  • TypeScript를 활용해 프로젝트의 필요한 곳에 타입을 명시해 주세요.
  • any 타입의 사용은 최소화해 주세요.
  • 복잡한 객체 구조나 배열 구조를 가진 변수에 인터페이스 또는 타입 별칭을 사용하세요.
  • Union, Intersection, Generics 등 고급 타입을 적극적으로 사용해 주세요.
  • 타입 별칭 또는 유틸리티 타입을 사용해 타입 복잡성을 줄여주세요.
  • 타입스크립트 컴파일러가 에러 없이 정상적으로 작동해야 합니다.

백엔드

  • 기존 Express.js 프로젝트를 타입스크립트 프로젝트로 마이그레이션 해주세요.
  • tsconfig.json 파일을 생성하고, 필요한 컴파일러 옵션을 설정해야 합니다. (예: outDir).
  • TypeScript 관련 명령어를 package.json에 설정해 주세요. (예: 빌드 및 개발 서버 실행 명령어).
  • ts-node와 nodemon을 사용하여 개발 환경을 구성합니다.
  • nodemon과 함께 ts-node를 사용하여 . ts 파일이 변경될 때 서버를 자동으로 재시작하도록 설정합니다.
  • Mongoose나 Prisma 등 ORM을 사용하는 경우, 모델에 대한 인터페이스 또는 타입을 정의합니다.
  • 필요한 경우, declare를 사용하여 타입을 오버라이드하거나 확장합니다.

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

Copy link
Collaborator

@kimjong95 kimjong95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 도메인모델에 대한 정의와 Requset, Response에 대한 타입정의가 이루어지지 않은것 같아요.

타입스크립트를 사용하는 이유는 프로젝트의 안정성을 높히는것 뿐만아니라 코드자체로도 어느정도의 문서화의 역할을 해주기 때문입니다. 잘 정의되어있는 타입들은 개발의 유지보수성도 향상시켜줍니다.

백엔드에서는 이러한 타입시스템을통해서 런타임에 발생할 수 있는 에러를 컴파일타임에 인지하고 해결할수 있게 도와줍니다. 다양한 유틸타입들도 활용하면 좋겠지만 현재는 말씀드린것처럼 모델, request, respnose들의 타입들을 지정해주시고, 공통으로 사용되는 타입들이있다면 묶어서 관리해보면 좋을 것 같습니다.

"skipLibCheck": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any타입에대한 경고를 띄울수있게 해당 옵션은 true로 두면 좋을것 같습니다!

});
}

async createProduct(userId: string, data: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data의 타입을 dto형태로 정의해서 사용해주세요!
또한 이렇게 dto타입으로 정했다면 class-validator 와같은 라이브러리로 validation처리도 추가할수 있습니다.

export �class CreateProductDto {
    name: string;
    description: string;
    price: number;
    like: number;
    imageUrl: string;
    userId: string
    tags: string[];
  }

@Query('search') search?: string,
@Query('pageSize') pageSize: string = '6',
) {
return this.articleService.getAllArticles(sort, search, Number(pageSize));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageSize를 string으로 받고, number로 캐스팅 하는 이유가 있을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants