[React] long type -> bigint

예구·2023년 5월 1일
0

자율PJT

목록 보기
2/2
post-thumbnail

1. 문제점

server에서 chatUnreadCound라는 변수를 long type으로 준다고 명시했다. 수가 너무 크다보니 int보다는 long을 사용한다던데 그럼 React는 이걸 어떻게 받아야 할까?



2. 해결방법

답은 Bigint다!

export interface RoomListType {
  roomId: number;
  roomName: string;
  petName: string;
  petLv: number;
  petPoint: number;
  petImageObjKey: string;
  friendFirstName: string;
  friendLastName: string;
  friendProfileImageObjKey: string;
  lastUpdatedTime: string;
  chatUnreadCount: bigint;
}

이렇게 타입은 bigint로 받고, 쓸 때는 toString()으로 바꿔서 사용해야 한다.

toString()을 사용하지 않으면 아래와 같은 에러가 발생한다.

No overload matches this call.
  Overload 1 of 2, '(props: TextProps | Readonly<TextProps>): Text', gave the following error.
    Type 'bigint' is not assignable to type 'ReactNode'.
  Overload 2 of 2, '(props: TextProps, context: any): Text', gave the following error.
    Type 'bigint' is not assignable to type 'ReactNode'.

따라서 아래와 같이 작성하면 해결!

profile
우당탕탕 FE 성장기

0개의 댓글