我是打字/反应新手。我遇到此类型错误,在该错误之下,我不确定如何解决。有人可以启发我吗?
错误: [tsc] src / webparts / jsonFeed / components / JsonFeed.tsx(40,8):错误TS2322:键入'{postOrLinkedIn:any; }'不可分配给'ReactElement ReactElement ReactElement类型
JsonFeed.tsx
export default class JsonFeed extends React.Component<IJsonFeedProps, IJsonFeedState> {
// State needed for the component
constructor(props) {
super(props);
this.state = {
description: this.props.description,
posts: [],
profile: {},
isLoading: true,
jsonUrl: this.props.jsonUrl, // This was just for testing purposes
postCount: this.props.postCount,
errors: null,
error: null,
listName: this.props.listName, // This will actually select the list
item: this.props.item, // This will actually select the list
};
}
// Renders to the browser
public render(): React.ReactElement<IJsonFeedProps> {
let postOrLinkedIn;
if (this.props.item !== 'linkedin') {
postOrLinkedIn = <Posts />;
} else {
postOrLinkedIn = <Linkedin />;
}
// What we render
return (
{postOrLinkedIn}
);
}
}
IJsonFeedProps:
export interface IJsonFeedProps {
description?: string;
postCount?: number;
jsonUrl?: string;
listName?: string;
item?: string;
posts?: any;
postOrLinkedIn?: boolean;
}
答案 0 :(得分:0)
您已在IJsonFeedProps
中指定postOrLinkedIn
是未定义或布尔值。而在render函数中,您将返回JSX.Element
。