Closed
Description
Bug Report
π Search Terms
React component default generic type
π Version & Regression Information
- This is an error
β― Playground Link
Playground link with relevant code
π» Code
import React from 'react'
import {
ComponentPropsWithRef,
ElementType,
ReactNode,
} from 'react'
type ButtonBaseProps<T extends ElementType> =
ComponentPropsWithRef<T> & {
children?: ReactNode
}
function Component<T extends ElementType = 'span'>(props: ButtonBaseProps<T>) {
return <></>
}
const v1 = <Component onClick={e => e.preventDefault()} /> // <- Error
const v2 = <Component<'span'> onClick={e => e.preventDefault()} /> // <- Ok
π Actual behavior
Default generic type is not inherited in callbacks, but intellisense works fine:
π Expected behavior
Should work both variants