如何指定具有子对象的接口作为具有分解道具的函数的类型

时间:2020-07-08 19:16:56

标签: typescript

相反,

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;
}

2 个答案:

答案 0 :(得分:1)

这很好用,您的示例在我的计算机上不起作用的唯一原因是因为list中没有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");
};

答案 1 :(得分:0)

import { client } from "./setupApi";

export interface IGetLayoutProps {
  page: string;
  entity: string;
  layout?: string;
  list?: Array<string>;
}

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