Skip to content

Commit

Permalink
fix(defineComponent): defaultProps 定义优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jul 21, 2020
1 parent 1b34fe3 commit 86cf2ef
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/react/defineComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Defined, OptionalKeys, RequiredBy } from '../types'
import { OptionalKeys } from '../types'

/**
* 定义组件的选项。
Expand Down Expand Up @@ -29,7 +29,7 @@ export type DefineComponentOptions<
* 可选属性的默认值。
*/
defaultProps: {
[K in OptionalKeys<TProps>]: Defined<TProps[K]>
[K in OptionalKeys<TProps>]?: TProps[K]
}
}) &
(TForwardRef extends true
Expand All @@ -53,11 +53,8 @@ export type DefineComponentOptions<
* 组件。
*/
component: TForwardRef extends true
? React.ForwardRefRenderFunction<
TRef,
Omit<RequiredBy<TProps, keyof TProps>, 'key' | 'ref'>
>
: React.FC<Omit<RequiredBy<TProps, keyof TProps>, 'key' | 'ref'>>
? React.ForwardRefRenderFunction<TRef, Omit<TProps, 'key' | 'ref'>>
: React.FC<Omit<TProps, 'key' | 'ref'>>
}

/**
Expand Down

0 comments on commit 86cf2ef

Please sign in to comment.