로고로고

meta 데이터 타입 에러

2025년 2월 24일

문제점

src/app/(after-login)/dashboard/[id]/page.tsx
Type error: Type '{ params: { id: string; }; }' does not satisfy the constraint 'PageProps'.
  Types of property 'params' are incompatible.
    Type '{ id: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]

원인

해결 방법

export async function generateMetadata({ params }: { params: { id: string } }): Promise<Metadata> {
  const id = params.id;// 이 부분에서 단순 객체로 처리하여 타입 불일치 발생

export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
  const { id } = await params;// 수정

 

 

resolved 객체란 Promise를 await를 사용하여 처리한 후, Promise가 이행(fulfilled)되어 반환한 실제 값

여기서 params는 Promise<{ id: string }> 타입이라면, await params는 Promise가 이행되어 반환하는 { id: string } 객체가 됩니다. 이 { id: string } 객체를 "resolved 객체"라고 부릅니다.

즉, Promise가 완료된 후 실제로 사용할 수 있는 값(객체)을 의미합니다.