Skip to content
Advertisement

Creating a new object in Typescript is giving an error that it requires an extra comma [closed]

I have the following classes:

export class datalist
{
    data: mydata[];
}

export class mydata
{
    data1: string;
    data2: string;
}

I’m trying to create these types using the following syntax:

const mydatalist: datalist = {
  ...new datalist(),
  data: this.somedata.map(function(x, i) {
    return {          
      data1: x.somedata1, 
      data2: x.somedata2 
    };
  }
};

However, I get the following error:

‘,’ expected

Please could someone point me to what I’m doing wrong?

Advertisement

Answer

You’re not closing your map() function.

const mydatalist: datalist = {
  ...new datalist(),
  data: this.somedata.map(function(x, i) {
    return {          
      data1: x.somedata1, 
      data2: x.somedata2 
    };
  })   <<-- here
};
Advertisement