-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do this
Milestone
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
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do this