[英]Object is of type "unknown" in interfaces
I'm creating project in Laravel 8 + Vue 3 with Typescript and Inertia我正在使用 Typescript 和 Inertia 在 Laravel 8 + Vue 3 中创建项目
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:有我的身份验证和用户界面:
export interface UserInterface {
id: number
name: string
email: string
}
export interface AuthInterface {
user?: UserInterface
}
When I console.log
without .user
, everythink is fine.当我
console.log
没有.user
时,everythink 都很好。
There is my usePage
function:有我的
usePage
function:
import {usePage as inertiaUsePage} from "@inertiajs/inertia-vue3";
export const usePage = () => {
return inertiaUsePage<PageProps>();
}
export interface PageProps {
auth: AuthInterface
}
我已经重现了您的错误,我发现您还需要安装vue3
和@inertiajs/inertia
才能使类型正确。
You can add any as a type, this will replace unknown type:您可以添加任何类型,这将替换未知类型:
usePage<any>()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.