[@types/react] The remove of onPointerEnterCapture caused unexpected errors. #69006
-
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 complex type that with 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.
Reason:The forwardRef function performs an 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 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 the usage of the component in project B demands that onPointerCapture must be provided. In a project, numerous npm packages are used. If an npm package depends on an older version of @types/react, and the project that uses this package requires a newer version (for instance, the version specified for @types/react in the package.json devDependencies field is "17.x" or "latest"), then the issue described above will occur when developers simply run |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 9 replies
-
Thanks for the discussion about "react", some useful links for everyone: Pinging the DT module owners: @johnnyreilly, @bbenezech, @pzavolinsky, @ericanderson, @DovydasNavickas, @theruther4d, @guilhermehubner, @ferdaber, @jrakotoharisoa, @pascaloliv, @Hotell, @franklixuefei, @Jessidhia, @saranshkataria, @lukyth, @eps1lon, @zieka, @dancerphil, @dimitropoulos, @disjukr, @vhfmag, @hellatan, @priyanshurav, @Semigradsky, @mattpocock. |
Beta Was this translation helpful? Give feedback.
-
I have created a revert PR to roll back @types/react to its previous state, in order to avoid having everyone encounter this error after updating their dependencies. #69005 |
Beta Was this translation helpful? Give feedback.
-
Multiple versions of the React types in a single application are not supported just like mutliple versions of React in an app are not supported. Could you provide a full, minimal example that shows the issue? |
Beta Was this translation helpful? Give feedback.
-
I encountered this issue a few days ago too! It turned out to be caused by an upgrade of the @types/react version, which cost me half a day! |
Beta Was this translation helpful? Give feedback.
-
👍 Seeing exactly the same type of error with a recent update to @types/react 17.0.78.
|
Beta Was this translation helpful? Give feedback.
-
I'll revert this for the older type versions since those will most likely not be fixed since it would require re-publish of the affected libraries with the latest 17.x types. The change stays for React 18 types though. Backports should be reserved for critical bug fixes and given how long we had this bug in, it doesn't seem critical. If you're affected, please follow microsoft/TypeScript#57779 as well. |
Beta Was this translation helpful? Give feedback.
-
As for work around we are using this type augmentation. // src/global.d.ts
import 'react'
declare module 'react' {
interface HTMLAttributes<T> {
onPointerEnterCapture?: (e: React.PointerEvent<T>) => void
onPointerLeaveCapture?: (e: React.PointerEvent<T>) => void
}
interface RefAttributes<T> {
onPointerEnterCapture?: (e: React.PointerEvent<T>) => void
onPointerLeaveCapture?: (e: React.PointerEvent<T>) => void
}
} |
Beta Was this translation helpful? Give feedback.
-
So... Is there any update on workarounds besides using type augmentation to put the removed properties back? It's extremely annoying, and the task we're told to follow doesn't exactly help. |
Beta Was this translation helpful? Give feedback.
I'll revert this for the older type versions since those will most likely not be fixed since it would require re-publish of the affected libraries with the latest 17.x types. The change stays for React 18 types though.
Backports should be reserved for critical bug fixes and given how long we had this bug in, it doesn't seem critical.
If you're affected, please follow microsoft/TypeScript#57779 as well.