Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 扩展接受的道具类型_Reactjs_Typescript - Fatal编程技术网

Reactjs 扩展接受的道具类型

Reactjs 扩展接受的道具类型,reactjs,typescript,Reactjs,Typescript,我有一个组件,它的根节点可以被passed prop的值覆盖 界面道具{ propA?:字符串 as?:React.ElementType } 常量可重写组件=(道具:道具)=>{ const{as:Tag='div',…otherProps}=props 返回 } 以及另一个将用作的组件 interface-SomeComponentProps{ propB:string//{ 返回{props.children} } 所以,我想要达到的结果是这样的 我希望OverridableCom

我有一个组件,它的根节点可以被passed prop的值覆盖

界面道具{
propA?:字符串
as?:React.ElementType
}
常量可重写组件=(道具:道具)=>{
const{as:Tag='div',…otherProps}=props
返回
}
以及另一个将用作的组件

interface-SomeComponentProps{
propB:string//{
返回{props.children}
}
所以,我想要达到的结果是这样的


我希望
OverridableComponent
合并
SomeComponent
中的道具


是否可以将所需的
React.ElementType
明确地传递为?这样做,您就不依赖于编译器推理,并且可以适当地缩小类型

组成部分:

const AppWithComponent = () => (
  <OverridableComponent<typeof SomeComponent>
    propA="pa"
    propB="pb"
    // className="ajsf" ; error 
    // from='string' ; error
    as={SomeComponent}
  />
);
const-AppWithComponent=()=>(
);
固有元素:

const AppWithIntrinsicElementExplicit = () => (
  <OverridableComponent<"div">
    propA="pa"
    // propB="pb" ; error
    className="yehaa"
    // from='string' ; error
    as="div" // you also can drop this attribute
  />
);
const-AppWithIntrinsicElementExplicit=()=>(
);

好吧,我想避免在jsx中使用类型,但这是一个选项,谢谢