I am using React and my VSCode keeps showing me this error :
Binding element 'profil' implicitly has an 'any' type.ts(7031)
For this code :
function Item({profil}) {
return (
<div>
{profil.name}
</div>
);
}
export default Item;
The code works, it's displaying what I'm expecting, but I cannot get ride of this error in VSCode, except when I change the function to :
function Item({profil}: any) {
Edit (final solution) : there are ways to get ride of this error with some TypeScript
configs, but I'll use interfaces since it seems to be a best practice. It will also help my team to understand each component when they'll jump in the project.
Here is the final solution working for my case :
interface ItemProps {
id: number;
name: string;
}
function Item({profil}: ItemProps) {
return <div>
{profil.name}
</div>
}
TypeScript is not able to infer the type of the profil prop in your function, so it assumes it has the 'any' type. You should either define an interface or type for the profil prop.
type Profil = {
name: string;
};
interface Profil {
name: string;
}