-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
π Search Terms
polymorphic component, react component prop inference
π Version & Regression Information
I noticed this 4.5.2, not sure how far the issue goes back or if it ever worked.
β― Playground Link
Playground link with relevant code
π» Code
import React from 'react'
type ComponentOrHTMLTag = keyof JSX.IntrinsicElements | React.ComponentType<any>;
type CustomComponentProps<
ActualComponent extends ComponentOrHTMLTag,
ActualComponentProps = React.ComponentProps<ActualComponent>
> = ActualComponentProps & {
component?: ActualComponent;
};
interface CustomComponent<
FallbackComponent extends ComponentOrHTMLTag,
> {
<ActualComponent extends ComponentOrHTMLTag = FallbackComponent>(
props: CustomComponentProps<ActualComponent>
): React.ReactElement<CustomComponentProps<ActualComponent>>;
}
const Field = ({component: Component = 'input', ...props}: {component: ComponentOrHTMLTag}) => <Component {...props} />
export const DSField: CustomComponent<'input'> = Field;
type Item = {
name: string
}
const ToyInputWithFunctionProp = ({ exampleFunction, item, ...props }: { exampleFunction: (item: Item) => string, item: Item}) => <input data-thing={exampleFunction(item)} {...props} />
function main() {
return (
<DSField component={ToyInputWithFunctionProp} exampleFunction={item => item.name} item={{ name: 'foo'}} />
)
}
π Actual behavior
Error: Parameter 'item' implicitly has an 'any' type.
π Expected behavior
item
should retain its type Item
Tf you hover on exampleFunction
to get the intellisense for it, the correct type is observed. It seems to be lost on the interpolated JSX value.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created