相关文章推荐
伤情的墨镜  ·  element日期选择器,结束日期不可小于开 ...·  2 年前    · 
傲视众生的佛珠  ·  不可不知的 Vue.js 列表渲染 - 知乎·  2 年前    · 
难过的板凳  ·  python opencv 三维重建图形-掘金·  2 年前    · 
酒量大的莲藕  ·  GDI+ resets color of ...·  2 年前    · 
文雅的香槟  ·  JS正则表达式语法大全(非常详细)·  2 年前    · 
Code  ›  类型记录没有重载与此调用react.cloneElement匹配开发者社区
https://cloud.tencent.com/developer/ask/sof/107141286
瘦瘦的海豚
2 年前
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
提问
问 类型记录没有重载与此调用react.cloneElement匹配
Stack Overflow用户
提问于 2022-07-20 09:55:42
EN

我在我的React.cloneElement第一个参数"childred“上的反应代码中有一个类型记录错误,我不明白。

我认为在index.d.ts for cloneElement中定义的类型不适用于这种情况,但是我对类型记录非常陌生,我如何才能修复它呢?index.d.ts中的"P“、"T”代表什么?

MessageType.tsx:

class MessageType extends React.Component<any, any> {
 [.....]
const { children, noFloating } = this.props ;
  [.....]
{messageType
              ? React.cloneElement(children, {
                  ...(noFloating ? {} : { floatingMessage }),
                  messageType,
                  message: `Example ${messageType} message`,
              : children}

在上面这段代码中,“子”是红色的。

错误:

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'ReactNode' is not assignable to parameter of type 'FunctionComponentElement<P>'.
      Type 'undefined' is not assignable to type 'FunctionComponentElement<P>'.ts(2769)
index.d.ts(328, 14): The last overload is declared here.

index.d.ts:

/ Custom components
function cloneElement<P>(
    element: FunctionComponentElement<P>,
    props?: Partial<P> & Attributes,
    ...children: ReactNode[]): FunctionComponentElement<P>;
function cloneElement<P, T extends Component<P, ComponentState>>(
    element: CElement<P, T>,
 
推荐文章
伤情的墨镜  ·  element日期选择器,结束日期不可小于开始日期(详解)_筛选条件截止时间不能小于开始时间_べJL的博客-CSDN博客
2 年前
傲视众生的佛珠  ·  不可不知的 Vue.js 列表渲染 - 知乎
2 年前
难过的板凳  ·  python opencv 三维重建图形-掘金
2 年前
酒量大的莲藕  ·  GDI+ resets color of transparent part of image to black - Stack Overflow
2 年前
文雅的香槟  ·  JS正则表达式语法大全(非常详细)
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号