'Typescript React: function props return type not working
- This is the base component Button.
export interface IButtonProps {
onTap: () => void;
}
export function Button(props: IButtonProps) {
return <div>demo</div>;
}
- This is HOC component Footer.
I hope the item's return type is 'type of Button'.
interface IFooterProps {
items: () => Array<React.ReactElement<IButtonProps, typeof Button>>;
}
export function Footer(props: IFooterProps) {
const items = props.items();
return (
<div>
footer
</div>
);
}
- Usage
<Footer
items={() => [
<div></div> // I expect an error here
]}
/>
How can I type the prop items properly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
