preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.35k stars 1.93k forks source link

compat: Improve React compatibility for `Ref` type. #4403

Closed maxbrieiev closed 1 month ago

maxbrieiev commented 1 month ago

In React, the Ref type corresponds to the Ref type in preact core. However, preact/compat re-exports the Ref type from preact/hooks instead of from core.

The following snippet does not produce a type error in React, but it does when using preact:

export const baz = (
  ref: React.ForwardedRef<HTMLElement>
): React.Ref<HTMLElement> => ref;

In preact it producesType 'ForwardedRef<HTMLElement>' is not assignable to type 'Ref<HTMLElement>'.

This pull requests fixes this issue.

coveralls commented 1 month ago

Coverage Status

coverage: 99.611%. remained the same when pulling 92fd386204efed31a8f5fb3cc596652bd42227ef on maxbrieiev:main into d19017e906a204f20c96137b8561a4c10233343e on preactjs:main.