Rajesh
Rajesh 👨🏻‍💻developer, architect, consultant focussed on modernization, cognitive services, and conversational ai.

SharePoint Framework: error TS2339: Property items does not exist on type Readonly

SharePoint Framework: error TS2339: Property items does not exist on type Readonly

When you encounter the below error, while using state object in react based webpart created by yeoman generator.

error TS2339: Property ‘items’ does not exist on type ‘Readonly<{}>’

Follow these steps

  1. Create an interface with the state objects as properties, as below
    1
    2
    3
    4
    
    export interface IQuoteState {
      error?: string;
      quoteItems?: IQuoteItem[];
    }
    
  2. 2.Use the interface in your component class as below
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    export default class Quotes extends React.Component<IQuoteProps, IQuoteState> {
    constructor(props) {
     super(props);
     this.state = {
       error: null,
       censusItems: []
     };
      }
    }
    

comments powered by Disqus