typescript 리팩토링(1)

라형선·2023년 3월 22일
0

DetailPage 오류 1

id가 그냥 변수명인 줄 알았는데 useParams에서 가져오는 값이었다.

const { id } = useParams();

const id: string | undefined 이라고 나왔지만
'Readonly<Params>' 형식은 'string' 형식에 할당할 수 없습니다.
라고 하여 any타입을 주었다.

DetailPage 오류 2


p값이 undefined일 수 있다고 하여서 조건문으로 한번 걸러주었다.

    if (post !== undefined) {
      let p = post;
      p.LikedUsers.push(userUid);

      updateDoc(doc(dbService, 'Post', id), {
        LikedUsers: p.LikedUsers,
      });
    }
profile
형선

0개의 댓글