Laravel по-русски

Русское сообщество разработки на PHP-фреймворке Laravel.

Ты не вошёл. Вход тут.

#1 Re: Laravel 6/7/8/9/10 » Laravel 12 React TypeScript StarterKits Default Layout » 04.06.2025 11:18:32

The any type, while it makes the error disappear, isn't ideal for type safety. The core of the problem is that TypeScript doesn't inherently know the structure of the module resolved by resolvePageComponent, particularly that it will have a default export which is a React component and might have a layout property.

To fix this, you should define a specific interface for your Inertia page components, let's call it InertiaPageComponent. This interface would extend ComponentType<any> (a better type for React components than ComponentProps) and include an optional layout property. Then, explicitly tell TypeScript that resolvePageComponent will return a Promise that resolves to an object with a default export of type InertiaPageComponent. This way, you provide the necessary type information, allowing PhpStorm to understand the module's structure and eliminate the red line while maintaining type safety.

Подвал раздела