[英]Typescript object literal may only specify known properties error
I am new to typescript/react.我是打字稿/反应的新手。 I have this type error below which I am unsure on how to tackle.
我有这种类型的错误,我不确定如何解决。 Can anybody enlighten me?
有人可以启发我吗?
Error: [tsc] src/webparts/jsonFeed/components/JsonFeed.tsx(40,8): error TS2322: Type '{ postOrLinkedIn: any;错误:[tsc] src/webparts/jsonFeed/components/JsonFeed.tsx(40,8):错误 TS2322:类型 '{ postOrLinkedIn: any; }' is not assignable to type 'ReactElement ReactElement ReactElement
}' 不可分配给类型 'ReactElement ReactElement ReactElement
JsonFeed.tsx 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: IJsonFeedProps:
export interface IJsonFeedProps {
description?: string;
postCount?: number;
jsonUrl?: string;
listName?: string;
item?: string;
posts?: any;
postOrLinkedIn?: boolean;
}
You have specified in IJsonFeedProps
that postOrLinkedIn
is either undefined or a boolean.您已在
IJsonFeedProps
中指定postOrLinkedIn
未定义或 boolean。 Whereas in the render function you are returning a JSX.Element
.而在渲染 function 中,您返回的是
JSX.Element
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.