I am new to js/ts but experienced in C#. Now I'm learning React and want to use typescript. I try to add types to this demo project: https://github.com/bradtraversy/projectmanager/tree/master/src .
export interface IProjects {
projects: IProjectItem[];
}
export interface IProjectItem {
title: string;
category: string;
}
class Projects extends React.Component<IProjects,object> {
constructor(props: IProjects) {
super(props);
}
render() {
let projectItems = this.props.projects.map( project => {
return (
<ProjectItem project={project} /> //Error: the type "{ project: IProjectItem; }" is not assignable to "Readonly<IProjectItem>"
);
});
...
}
class ProjectItem extends React.Component<IProjectItem,object> {
...
}
What I thought is that "project" within the arrow function is of type "IProjectItem" and that's the right type for the component "ProjectItem". It seems I'm doing something wrong with the used types. I only have added types to the example mentioned above as video from https://www.youtube.com/watch?v=A71aqufiNtQ ( @ ~ 21:06 ) What are the right types using the given example?
return (<ProjectItem project=project />)? It seems like it doesn't like you wrapping theIProjectItemin an object.