繁体   English   中英

Typescript 错误:类型中缺少属性“children”,但类型“CommonProps”中是必需的

[英]Typescript error: Property 'children' is missing in type but required in type 'CommonProps'

第一次看到这样的错误,请多多包涵。

我正在处理一个项目并打开一个文件进行更改。 我打开了文件,实际上并没有做任何更改,只是使用 Prettier 格式化了文件。

就在它格式化时,该项目引发了以下错误:

TypeScript error in C:/Users/name/source/repos/UsedEquipment/src/pages/listings/sections/SearchResultListings.tsx(253,16):
Type '{ style: { height: string; }; type: "rect"; ready: false; showLoadingAnimation: true; }' is not assignable to type '(IntrinsicAttributes & CommonProps & { color?: string | undefined; rows?: number | undefined; showLoadingAnimation?: boolean | undefined; customPlaceholder?: undefined; } & Pick<...> & { ...; } & { ...; }) | ... 4 more ... | (IntrinsicAttributes & ... 2 more ... & { ...; })'.
  Property 'children' is missing in type '{ style: { height: string; }; type: "rect"; ready: false; showLoadingAnimation: true; }' but required in type 'CommonProps'.  TS2322

这是引发错误的代码:

showPlaceholders() {
    let items: Object[] = [];
    for (let i = 0; i < ITEMSPERPAGE; i++) {
      //show # of placeholders
      items.push(
        <div
          className="productwrap col-xs-12 col-sm-4 col-md-4 col-lg-3 placeholder"
          key={i}
        >
          <div className="product-wrapper">
            <div className="product-image">
              <ReactPlaceholder
              ^ Error thrown here
                style={{ height: "180px" }}
                type="rect"
                ready={false}
                showLoadingAnimation={true}
              ></ReactPlaceholder>
            </div>
            <div className="product-info-column">
              <ReactPlaceholder
              ^ Error thrown here
                type="text"
                rows={6}
                ready={false}
                showLoadingAnimation={true}
              ></ReactPlaceholder>
            </div>
          </div>
        </div>
      );
    }
    return items;
  }

我不完全确定这个错误是什么意思或如何解决它。 任何想法?

React Placeholder 需要一个子组件 在其中传入任何有效的 html 标签。

<ReactPlaceholder { /*...your other optional props */ }>
  <MyComponent /> {/* this is mandatory */ }
</ReactPlaceholder>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM