I want to iterate over a generic interface. And use the value of the object in jsx. But Typescript throws the following:
Argument of type '(key: K) => JSX.Element' is not assignable to parameter of type '(value: string, index: number, array: string[]) => Element'.
interface Props<T> {
object: T;
}
export default function BasicInputs<T, K extends keyof T>({
object,
}: Props<T>): ReactElement {
return (
<div>
{Object.keys(object).map((key: K) => (
<div>
<div className="">
<input
value={object[key]}
type="text"
name="name"
id="name"
/>
</div>
</div>
))}
</div>
);
}
How should I define the interface and component for correct typing?