简体   繁体   English

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

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

First time seeing an error like this so please bear with me.第一次看到这样的错误,请多多包涵。

I was working on a project and opened one file to make a change.我正在处理一个项目并打开一个文件进行更改。 I opened the file, didn't actually make any change and just formatted the file using Prettier.我打开了文件,实际上并没有做任何更改,只是使用 Prettier 格式化了文件。

Right when it formatted, the project threw the error below:就在它格式化时,该项目引发了以下错误:

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

Here's the code where the error's thrown:这是引发错误的代码:

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;
  }

I'm not entirely sure what this error means or how to fix it.我不完全确定这个错误是什么意思或如何解决它。 Any idea?任何想法?

React Placeholder expects one child component . React Placeholder 需要一个子组件 Pass in any valid html tag inside it.在其中传入任何有效的 html 标签。

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

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

相关问题 TypeScript 错误:类型中缺少属性“0” - TypeScript Error: Property '0' is missing in type 属性“儿童”的类型缺失 - Property 'children' is missing in type 类型中缺少 TypeScript 属性“导航”,但类型“道具”React Native 中需要 - TypeScript Property 'navigation' is missing in type but required in type 'Props' React Native "<i>TypeScript error: Property &#39;children&#39; does not exist on type &#39;{ children?: ReactNode;<\/i> TypeScript 错误:类型 &#39;{ children?: ReactNode; 上不存在属性 &#39;children&#39;<\/b> <i>}&#39;<\/i> }&#39;<\/b>" - TypeScript error: Property 'children' does not exist on type '{ children?: ReactNode; }' 类型中缺少属性,但类型中需要属性 - Property is missing in type but required in type typescript 给出的属性缺少类型 - typescript gives property is missing a type React + Typescript:类型*中缺少属性* - React + Typescript: Property * is missing in type * 类型“{}”中缺少属性“submitAction”,但在类型中是必需的 - Property 'submitAction' is missing in type '{}' but required in type Testcafe Applitools 打字稿 - 错误:类型中缺少属性“accessibilityValidation” - Testcafe Applitools typescript - Error: Property 'accessibilityValidation' is missing in type 类型中缺少属性“previous”-TypeScript + ReactJS - Property 'previous' is missing in type - TypeScript + ReactJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM