繁体   English   中英

Typescript object 文字可能只指定已知属性错误

[英]Typescript object literal may only specify known properties error

我是打字稿/反应的新手。 我有这种类型的错误,我不确定如何解决。 有人可以启发我吗?

错误:[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;
}

您已在IJsonFeedProps中指定postOrLinkedIn未定义或 boolean。 而在渲染 function 中,您返回的是JSX.Element

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM