typescript - 打字稿推断返回对象
问题描述
我正在创建如下所示的设置函数:
type Setup<T> = (overrideProps?: Partial<T>) => void /* WHAT HERE */;
const setup: Setup<ProductProps> = (overrideProps) => {
const props: ProductProps = {
oldPrice: 9000,
price: 8490,
...overrideProps,
};
const component = <Product {...props} />;
return {
component: testRenderer.create(component),
props,
};
};
我想输入可以不同的返回值,但有一件事是肯定的,函数将返回props
变量,其他是可选的。
怎么打字?
解决方案
推荐阅读
- python - 包的导入错误,我是否缺少 __init__.py
- c++ - 通过元素指针的无序映射作为键对向量进行排序
- c# - dll 和 pdb 未在 bin/debug 文件夹中创建
- python - 使用 Keras flow_from_dataframe 解决多输出回归问题
- registration - 使用 pip 找不到 Elastix
- python - 使用 numpy 和 matplotlib 从 CSV 文件生成热图 - 如何在轴上显示负数
- javascript - 如何在 React 应用程序(CRA)中从 jQuery 加载 $ 函数?
- node.js - Hapi 抱怨缺少安装的插件依赖项
- android - 无法解析 Zendesk 库
- python - 如何在熊猫中使用 pd.grouper 和 groupby