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 (将#修改为@)