打字稿|属性“ something”在类型“ IntrinsicAttributes&Props”上不存在

时间:2019-04-08 07:14:23

标签: javascript reactjs typescript components tsc

我正在编写一个TypeScript容器组件,在那里我也使用TS中制作的一些组件。编译器将引发以下警告:

index.tsx:256:12 - error TS2322: Type '{ className: string; data-test: string; items: { name: string; url: string; }[]; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'className' does not exist on type 'IntrinsicAttributes & Props'.

问题是我不确定这有什么问题。我看了d.types中的JSX.Elem ent定义。并找到了这个

// tslint:disable-next-line:no-empty-interface
interface IntrinsicAttributes extends React.Attributes { }
// tslint:disable-next-line:no-empty-interface
interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> { }

我倒在上面的组件中,通常有4个都带有类似的错误。在这里,您可以找到有关如何使用组件的参考。请记住,此render方法不是通用的render方法,我也在那里调用

  renderStaticPageComponents = (): JSX.Element => (
    <Fragment>
      <div className="row">
        <div className="col">
          <Breadcrumb
            className="py-2"
            data-test="basic-mode-breadcrumb"
            items={[{ name: 'Admin', url: '' }, { name: 'Users', url: '/management/users' }]}
          />
        </div>
        <div className="col-auto">
          <a href="#" rel="noopener noreferrer" target="_blank">
            <Icon icon="question-circle-o" className="fa-lg" />
          </a>
        </div>
      </div>
      <PageHeader className="heading-title" dtata-test="basic-mode-header">
        Users
      </PageHeader>
    </Fragment>
  );

使用组件的所有渲染方法的类型均为JSX.Element | null。我以为如果删除它们,然后将它们保留为类型,那么编译器就不会大喊大叫,但是问题实际上出在其他地方。

您能给我解释一下这里的问题和解决方案吗?也许我需要另一个JSX ....类型的这类渲染器?谢谢!!

0 个答案:

没有答案
相关问题