-
Notifications
You must be signed in to change notification settings - Fork 30.6k
[@types/react] The remove of onPointerEnterCapture caused unexpected errors. #69004
Description
Yesterday, @types/react released a new version which removed onPointerEnterCapture. #68984
However, this change has resulted in unexpected errors.
A reproduction path:
Consider a project A that uses an older version of @types/react and exports a component wrapped with forwardRef, where the component's props type is a union that includes React.HTMLAttributes.
When this component is used in project B, which utilizes a newer version of @types/react, there will be an error indicating that the onPointerEnter property is missing.
error TS2739: Type '{ children: string; }' is missing the following properties from type 'Pick<IDemoProps, "slot" | "style" | "title" | "type" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | ... 249 more ... | "ellipsis">': onPointerEnterCapture, onPointerLeaveCapture
Reason:
The forwardRef function performs an Omit<props, 'ref'> operation on the props.
In the final type declaration file generated by project A, the Omit sometimes gets transformed into Pick. See #61757
If project A is using an old version of @types/react, this eventually turns into Pick<React.HTMLAttributes, ... | 'onPointerEnterCapture' | ...>.
Since project B is using a newer version of @types/react, where React.HTMLAttributes no longer includes onPointerEnterCapture, the onPointerEnterCapture is considered of an unknown type in the final prop types.
At this point, it becomes a required property, thus project B demands that onPointerCapture must be provided.
Not all npm packages will upgrade to the latest version of @types/react. When an npm package depends on an older version of @types/react, and the project using that npm package relies on a newer version, the issue described above will occur.