如何重写 react 的部分属性类型声明?

已经安装
"@types/react": "^17.0.52",

在global.d.ts中增加如下代码,可以重新声明 React.forwardRef 函数,但是同时react的其他属性就没有了

declare module 'react' {
  function forwardRef<T, P = {}>(
    render: (props: P, ref: React.Ref<T>) => React.ReactElement | null
  ): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
}

image.png

,如何在保留react其他属性的前提下,只重新声明其中一个属性。

阅读 2k
1 个回答
import "react";
declare module 'react' {
  function forwardRef<T, P = {}>(
    render: (props: P, ref: React.Ref<T>) => React.ReactElement | null
  ): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题