preact icon indicating copy to clipboard operation
preact copied to clipboard

fix(types): ensure `forwardRef` overrides the default ref type

Open aleclarson opened this issue 6 months ago • 1 comments

This fixes an issue with forwardRef that was leading to a type conflict, which was basically…

(Ref<HTMLDivElement> | undefined) // …from forwardRef's return type
  & (Ref<any> | undefined)        // …from the RenderableProps type

Try to assign the ref prop of a forwardRef component to a ref callback, its argument's type defaults to any no matter the component type.

Reproduction

/* @jsxImportSource preact */
import { forwardRef } from "preact/compat";

declare class Element {}

const Foo = forwardRef<Element>(() => {
	return <div />;
});

const element = <Foo ref={(node) => {}} />;
//                         ^? any (should be Element)

aleclarson avatar Jun 05 '25 23:06 aleclarson

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for CI

github-actions[bot] avatar Jun 05 '25 23:06 github-actions[bot]