naijacoder
naijacoder

Reputation: 464

error TS2339: Property 'items' does not exist on type 'Readonly<{}>'. usnig react in SPX

I'm working on a SPFX issue using react and I keep getting error :- Error - typescript - src\webparts\reactReadWebpart\components\ReactReadWebpart.tsx(101,25): error TS2339: Property 'items' does not exist on type 'Readonly<{}>'. See below screenshots

export 
default class
ReactReadWebpart
extends 
React.Component<IReactReadWebpartProps, {}> {

  public
constructor(props:
IReactReadWebpartProps,
state:
IReactReadWebpartState){ 

    super(props); 

    this.state
= {  

      items: [ 

        { 

         
"EmployeeName":
"", 

         
"EmployeeId":
"", 

         
"Experience":"", 

         
"Location":""

        } 

      ]  

    };  

  } 

error at state.items below

{this.state.items.map(function(item,key){ 

              

              
return (<div
className={styles.rowStyle}
key={key}> 

                  
<div
className={styles.CellStyle}>{item.EmployeeName}</div> 

                  
<div
className={styles.CellStyle}>{item.EmployeeId}</div> 

<div
className={styles.CellStyle}>{item.Experience}</div>

<div
className={styles.CellStyle}>{item.Location}</div>

        

                
</div>); 

             })} 

Thanks in advance

Upvotes: 0

Views: 3748

Answers (1)

Daniel Khoroshko
Daniel Khoroshko

Reputation: 2721

Setting the first-class code formatting in your question aside, you are getting the error because the component's state is described like as an empty object in this line

React.Component<IReactReadWebpartProps, {}> 

So you probably should define it so typescript will know what to expect. Some type or interfaces that will include items field will do.

Upvotes: 1

Related Questions