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;
}
解决方案
这工作得很好,你的例子在我的电脑上不起作用的唯一原因是因为没有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");
};
推荐阅读
- java - 如何实现像 Spring DispatcherServlet 这样的行为?
- python - 无法使用 flask-restful 设置蓝图
- java - 为什么 setOnCompletionListener 只被调用一次?
- oracle - 在不同的 Oracle 版本上使用加载器
- javascript - react-fullpage - 避免渲染中的 setState 无限循环
- python - 如何使用 tweepy 检索全文推文?
- mysql - 无法在 MySQL 事件调度程序正文中打开 SQL 脚本
- javascript - 即使样式隐藏,引导程序也保持 4 pic 一致
- javascript - 在 HTML5 输入字段的文本前添加键入数字的最佳方法?
- sinon - 带有ExactArgs的Sinon存根?