Witam, mam problem z przekazywaniem propsów jako obiekt. Większość tutoriali jest z przekazywaniem pojedyńczo wartości a nie obiektów. Przy przekazywaniu obiektu otrzymuje błąd:
Type '{ worker: { Name: string; Task: { Date: string; Project: string; Hours: number; Descriptions: string; }[]; }; }' is not assignable to type 'IntrinsicAttributes & Worker'.
Property 'worker' does not exist on type 'IntrinsicAttributes & Worker'.ts(2322)
const Main = () => {
let Andrzej = {
Name: "Andrzej",
Task: [{
Date: "13.02.2020",
Project: "React",
Hours: 5,
Descriptions: "Nic nie robiłem",
},{
Date: "13.02.2020",
Project: "TypeScript",
Hours: 3,
Descriptions: "Nic nie robiłem",
}]};
return (
<div className='main'>
<Table3 worker={Andrzej}></Table3>
</div>
);
}
export default Main;
Component:
import React from "react";
type Worker = {
Name: string,
Task: Array<Info>,
}
type Info = {
Date: string,
Project: string,
Hours: number,
Descriptions: string,
}
const Table3 = (worker:Worker) => {
return (
<> <div className="tbl-header">
<h1>{worker.Name}</h1>
<table>
<tr>
<th>Date</th>
<th>Project</th>
<th>Hours</th>
<th>Description</th>
</tr>
{worker.Task.map(x => (
<tr>
<td>{x.Date}</td>
<td>{x.Project}</td>
<td>{x.Hours}</td>
<td>{x.Descriptions}</td>
</tr>
))}
</table>
</div>
</>
);
};
export default Table3