UNPKG

dora-ui

Version:

A React.js Mobile UI Library

14 lines (13 loc) 825 B
import { ComponentType } from 'react'; /** * 目的:使得默认属性在类型定义中是可选的 * 但我们在组件实现中是必选的 */ export declare const withDefaultProps: <P extends object, DP extends Partial<P> = Partial<P>>(defaultProps: DP, Cmp: ComponentType<P>) => ComponentType<Partial<DP> & Required<Pick<P, Exclude<keyof P, keyof DP>>>>; /** * 默认属性不报错的另外一种实现方式 * 把可选的defaultProps的类型剔除后,加入必选的defaultProps的类型,从而形成一个新的Props类型, * 这个Props类型中的defaultProps相关属性就变成了必选的 * @param defaultProps 默认属性对象 */ export declare const createPropsGetter: <DP extends object>(defaultProps: DP) => <P extends Partial<DP>>(props: P) => DP & Pick<P, Exclude<keyof P, keyof DP>>;