[NestJS] 타입 지정하기

woogiemon·2023년 3월 13일
0
post-thumbnail
async insertTransact(request: InsertTransactRequest) {
    const sellUserName = request.SellUserName;
    const purchaseUserName = request.purchaseUserName;
    const product = request.product;

    const newTransact = this.transactRepository.create({
      purchaseUserName: purchaseUserName,
      sellUserName: sellUserName,
      product: product,
    });
}
export class InsertTransactRequest {
  @ApiProperty()
  @IsString()
  purchaseUserName: string;

  @ApiProperty()
  @IsString()
  SellUserName: string;

  @ApiProperty()
  @IsString()
  product: ProductBoardEntity;
}
@Entity('TRANSACT')
export class TransactEntity {
  @PrimaryGeneratedColumn({ name: 'TRNASACT_ID' })
  @Generated('increment')
  id: number;

  @ManyToOne(() => UserEntity, (user) => user.purchaseTransacts)
  @JoinColumn({ name: 'PURCHASE_USER_NAME' })
  purchaseUserName: UserEntity;

  @ManyToOne(() => UserEntity, (user) => user.sellTransacts)
  @JoinColumn({ name: 'SELL_USER_NAME' })
  sellUserName: UserEntity;

  @ManyToOne(() => ProductBoardEntity, (product) => product.transacts)
  product: ProductBoardEntity;

  @CreateDateColumn({ name: 'CREATE_AT' })
  created_at: Date;
}

에러코드

No overload matches this call.
  Overload 1 of 3, '(entityLikeArray: DeepPartial<TransactEntity>[]): TransactEntity[]', gave the following error.
    Argument of type '{ purchaseUserName: string; sellUserName: string; product: ProductBoardEntity; }' is not assignable to parameter of type 'DeepPartial<TransactEntity>[]'.
      Object literal may only specify known properties, and 'purchaseUserName' does not exist in type 'DeepPartial<TransactEntity>[]'.

21       purchaseUserName: purchaseUserName,

overloaded function에서 지정한 매개변수들의 타입 형식과 실제 전달한 인자의 타입 형식이 일치하지 않으면 뜨는 에러이다.

Entity 의 purchaseUser, sellUserName 의 타입은 NameUserEntity 인데,
DTO 의 타입은 string 이었기 때문에 생긴 오류!!!! 타입 실수하지말자!!!!

profile
삽질 기록..

0개의 댓글