usePage() not working on Typescript #973
Unanswered
krzar
asked this question in
Help (Vue)
Replies: 3 comments 1 reply
-
See here: #757 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I ran into this and ended up with this solution based on the above comment (@flick36). Hopefully it's correct, still learning the ropes for Inertia. // InertiaPage.d.ts
import { PageProps } from "@inertiajs/inertia";
interface DashboardPageProps extends PageProps {
community_leaders: User[]
}
// more below depending on the page rendered Then over in the dashboard: const communityLeaders = usePage<DashboardPageProps>().props.value.community_leaders |
Beta Was this translation helpful? Give feedback.
1 reply
-
Just declare this on top of your app (maybe your app.ts where Vue is initialised, dunno about React tho): declare module "@inertiajs/inertia" {
interface PageProps {
auth: {
user: Record<string | symbol, unknown> | null
}
}
}
// Then using it should show some autocompletion if properly configured in your IDE
usePage().props.value.auth.user?.name |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm creating project in Laravel 8 + Vue 3 with Typescript and Inertia
I got this error all the time
TS2571: Object is of type 'unknown'.
on this code
console.log(usePage().props.value.auth.user);
There is my auth and user interface:
When I console.log without .user, everythink is fine.
There is my usePage function:
Beta Was this translation helpful? Give feedback.
All reactions