mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-02 09:08:52 +08:00
14 lines
321 B
TypeScript
14 lines
321 B
TypeScript
import React from 'react'
|
|
|
|
const withDefaults = <P, DP>(
|
|
component: React.ComponentType<P>,
|
|
defaultProps: DP,
|
|
) => {
|
|
type Props = Partial<DP> & Omit<P, keyof DP>
|
|
component.defaultProps = defaultProps
|
|
|
|
return (component as React.ComponentType<any>) as React.ComponentType<Props>
|
|
}
|
|
|
|
export default withDefaults
|