【发布时间】:2019-05-21 14:15:18
【问题描述】:
我的问题有点像我之前的问题:ReactTS extend type by dynamic Component Props?
所以可以说我有下一行:
type Base = {
baseProp: ...
}
type Extend = {
extendProp: ...
}
// use this if "as" undefined
type DefaultPropsToExtend = {
defaultToExtendProp: ...
}
declare const ExtendedComponent: React.FC<Extend>
declare const DefaultExtendedComponent: React.FC<DefaultPropsToExtend>
function Base<T = DefaultPropsToExtend>(props: BaseProps & { as: React.ComponentType<T> } & T): React.ReactElement {
const Wrapper = props.as
return <Wrapper />
}
所以当我调用下一行时,我期望的是:
<Base /> // props can be => { baseProp, defaultToExtendProp }
What props actually I am seeing => { baseProp }
If I am doing the next then things working property, but this way I need to be explicit about the default "as" every time.
<Base as={DefaultToExtendComponent} /> // => { baseProp, defaultToExtendProp }
【问题讨论】:
标签: reactjs typescript typescript-typings