首页 > 解决方案 > 如何指定具有子对象的接口作为具有解构道具的函数的类型

问题描述

取而代之的是,

import { client } from "./setupApi";

export const getLayout = ({ page, entity, list }: {page: string, entity: string, list: string}) => {
  return client.get("/secure/nav.json");
};

我该如何使用这个界面?

export interface getLayoutProps {
  page: string;
  entity: string;
  layout: string;
}

标签: typescript

解决方案


这工作得很好,你的例子在我的电脑上不起作用的唯一原因是因为没有list属性 in getLayoutProps,而是有layout

export interface getLayoutProps {
  page: string;
  entity: string;
  layout: string;
}

export const getLayout = ({ page, entity, layout }: getLayoutProps) => { // This works.
  return client.get("/secure/nav.json");
};

推荐阅读