reactjs - 与 Omit 一起使用时,type Props 在 react 和 typescript 中的含义是什么?
问题描述
我是使用 typescript 和 react-dates 包的新手。
我不确定以下类型是什么意思
type Props = Omit<
DayPickerRangeControllerShape,
| 'numberOfMonths'
| 'focusedInput'
| 'onFocusChange'
| 'hideKeyboardShortcutsPanel'
| 'noBorder'
>;
function DateRangePicker(props: Props) {
return (
<Wrapper>
<DayPickerRangeController
{...props}
numberOfMonths={3}
onFocusChange={noop}
hideKeyboardShortcutsPanel
noBorder
horizontalMonthPadding={32}
dayPickerNavigationInlineStyles={{
display: 'flex',
justifyContent: 'space-between',
}}
</Wrapper>
);
}
在这种情况下,类型Props
withOmit
在这里做什么?
解决方案
这一行function DateRangePicker(props: Props)
意味着DateRangePicker
组件 props 应该与Props
之前定义的类型兼容。
而这块
type Props = Omit<
DayPickerRangeControllerShape,
| 'numberOfMonths'
| 'focusedInput'
| 'onFocusChange'
| 'hideKeyboardShortcutsPanel'
| 'noBorder'
>;
表示 typeProps
应该等于DayPickerRangeControllerShape
interface,但没有某些字段,例如numberOfMonths
等focusedInput
。
Omit
基本上从您传递给它的接口或类型中剥离(删除)一些字段。
推荐阅读
- passport.js - 如何使用护照和nestjs将api密钥作为请求url上的查询字符串传递
- flutter - POST 调用适用于 Postman,但不适用于 Flutter
- pdf - 从前端 -> 节点 js -> s3 将 pdf 上传到 s3
- reactjs - 清理不会防止查找具有相同角色的多个元素时出错
- jhipster - 如何为 jhipster 命令提供分析的默认值?
- python - 如何将列表的数据框列折叠成一个 NLP 列表
- html - Dompdf 创建一个包含 4 个相等部分的 A4 页面
- postgresql - 将 Postman 连接到 Postgres
- mysql - MySQL 根据电子邮件从表中获取 ID,然后使用 ID 和更多值在另一个表中创建一行
- java - 如果字符串为空,Java Firebase 不发送密码重置