Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse
exlends
Категории
  1. Home
  2. Categories
  3. Фронтенд
  4. NextJs
  5. PageProps Type Errors in Next.js. Type '{ slug: string; }' is missing the following properties from type 'Promise<any>'

PageProps Type Errors in Next.js. Type '{ slug: string; }' is missing the following properties from type 'Promise<any>'

Scheduled Pinned Locked Moved NextJs
errorsreactjs
1 Posts 1 Posters 359 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JspiJ Offline
    JspiJ Offline
    Jspi
    js
    wrote on last edited by admin
    #1

    После обновления Next js до 15 версии, в динамических маршрутах разработчики некоторые изменения, что приведет к ошибкам при сборке проекта.

    пример:

    Type error: Type 'Props' does not satisfy the constraint 'PageProps'.
      Types of property 'params' are incompatible.
        Type '{ slug: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]
    

    Разработчики сделали динамические параметры асинхронными, поэтому нужно будет поменять типы, и получать их мы должны, например, через await

    до 15 версии:

    
    // СТАРЫЙ КОД
    type Props = {
      params: {
        slug: string;
      };
    };   
    
    export async function generateMetadata({ params: { slug } }: Props) {
      const { category } = await fetchData(slug);
    
      ...
      }
    }
    
    export default async function Page({ params: { slug } }: Props) {
      const  data = await fetchData(slug);
    
      ...
    }
    

    после 15 версии:

    // НОВЫЙ КОД
    type Props = {
      params: Promise<{
        slug: string;
      }>;
    };  
    
    export async function generateMetadata(props: Props) {
      const { slug } = await props.params;
      const { category } = await fetchData(slug);
      ...
      }
    }
    
    export default async function Page(props: Props) {
      const { slug } = await props.params;
      const  data = await fetchData(slug);
      ...
    }
    

    Источник

    1 Reply Last reply
    👍
    2

    Категории

    • Главная
    • Новости
    • Фронтенд
    • Бекенд
    • Языки программирования

    Контакты

    • Сотрудничество
    • info@exlends.com
    • Наш чат
    • Наш ТГ канал

    © 2024 - 2025 ExLends, Inc. Все права защищены.

    Политика конфиденциальности
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups