微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Preact/Typescript/Enzyme:“Component<any, {}>”类型中缺少属性“refs”

如何解决Preact/Typescript/Enzyme:“Component<any, {}>”类型中缺少属性“refs”

我正在为一个使用 Preact、Typescript 和 Parcel 的项目配置 Jest。一切都在组件代码本身中工作,但是在设置 Jest 测试并使用 Enzyme 的 mountshallow 函数(使用 preact 适配器)渲染组件时,我收到一个错误,指示正在传递的类型进入函数缺少 ref 属性

src/features/homepage/homepage.spec.tsx:10:13 - error TS2769: No overload matches this call.
  Overload 1 of 3,'(node: ReactElement<any,string | JSXElementConstructor<any>>,options?: MountRendererProps | undefined): ReactWrapper<any,Readonly<...>,Component<...>>',gave the following error.
    Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any,string | JSXElementConstructor<any>>'.
      Types of property 'type' are incompatible.
        Type 'string | ComponentType<any>' is not assignable to type 'string | JSXElementConstructor<any>'.
          Type 'ComponentClass<any,{}>' is not assignable to type 'string | JSXElementConstructor<any>'.
            Type 'ComponentClass<any,{}>' is not assignable to type 'new (props: any) => Component<any,any,any>'.
              Property 'refs' is missing in type 'Component<any,{}>' but required in type 'Component<any,any>'.
  Overload 2 of 3,string | JSXElementConstructor<any>>'.
  Overload 3 of 3,unkNown,string | JSXElementConstructor<any>>'.

10             <Homepage/>
               ~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:501:9
    501         refs: {
                ~~~~
    'refs' is declared here.

@types/react 和 Enzyme 的最新版本有冲突吗?如果是这样,是否有一些覆盖此类型声明的最佳实践?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。