简体   繁体   English

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

[英]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.

相关问题 面对 Object 文字可能只指定 React Typescript 中的已知属性 - Faced Object literal may only specify known properties in React Typescript 对象字面量只能指定已知的属性,并且“任务”在类型“SetStateAction”中不存在 - Object literal may only specify known properties, and 'task' does not exist in type 'SetStateAction 对象字面量只能指定已知的属性,并且在类型 &#39;Headers&#39; 中不存在 &#39;&#39;app-id&#39;&#39; - Object literal may only specify known properties, and ''app-id'' does not exist in type 'Headers' 为什么我可以将未知属性分配给 typescript 中的文字 object? - Why can I assign unknown properties to literal object in typescript? 如何在使用 Typescript 时将样式化组件添加为 object 文字的属性? - How to add styled components as properties of an object literal while using Typescript? TypeScript:省略只读 object 文字 - TypeScript: Omit readonly object literal 类型断言对象字面量打字稿 - Type assertion object literal typescript 带Typescript抛出TypeError的React Relay(react-relay):对象原型只能是一个Object或为null:未定义 - React Relay (react-relay) with Typescript throwing TypeError: Object prototype may only be an Object or null: undefined 如何使用属性指定组件的打字稿类型 - How to specify typescript type of a component with properties 将具有给定属性的对象值显示为子项会产生错误 - React 和 Typescript - Displaying object values with given properties as children gives error - React and Typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM