【问题标题】:Object is of type "unknown" in interfaces对象在接口中属于“未知”类型
【发布时间】:2021-12-27 02:24:59
【问题描述】:

我正在使用 Typescript 和 Inertia 在 Laravel 8 + Vue 3 中创建项目

我一直收到这个错误

TS2571: Object is of type 'unknown'.

关于此代码

console.log(usePage().props.value.auth.user);

有我的授权和用户界面:

export interface UserInterface {
    id: number
    name: string
    email: string
}

export interface AuthInterface {
    user?: UserInterface
}

当我console.log 没有.user 时,一切都很好。

还有我的usePage函数:

import {usePage as inertiaUsePage} from "@inertiajs/inertia-vue3";

export const usePage = () => {
    return inertiaUsePage<PageProps>();
}

export interface PageProps {
    auth: AuthInterface
}

【问题讨论】:

  • 您还需要包含usePage 返回类型以正确告诉您问题所在
  • 我添加了我的 usePage 功能

标签: javascript laravel typescript vue.js inertiajs


【解决方案1】:

我已经重现了您的错误,我发现您还需要安装 vue3@inertiajs/inertia 才能使类型正确。

【讨论】:

  • 默认有打字,我没有找到任何vue3或惯性打字的包。
  • yarn add vue@3 @inertiajs/inertia
  • 不幸的是它没有帮助
猜你喜欢
  • 2019-09-23
  • 2020-09-02
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2011-08-26
  • 1970-01-01
  • 2021-07-31
  • 2022-01-21
相关资源
最近更新 更多