import type PropTypes from 'prop-types'; type Omit = Pick>; type Defined = T extends undefined ? never : T; /** * Get the type that represents the props with the defaultProps included. * * Alternatively, we could have done something like this: * ``` * export type WithDefaultProps> = Omit & * Required>>; * ``` * But there were usages of `null` in `defaultProps` that would need to be changed to `undefined` * to meet the `DP extends Partial

` constraint. * So, instead we take the union type in cases when a property in defaultProps does not extend * the corresponding property in the Props declaration. */ type WithDefaultProps = Omit & { [K in Extract]: DP[K] extends Defined ? Defined : Defined | DP[K]; }; /** * Get the props type from propTypes and defaultProps. * * Usage: * ``` * // Without defaultProps * type Props = PropsType; * * // With defaultProps * type Props = PropsType; * ``` */ export type PropsType = WithDefaultProps, DP>; export {};