简体   繁体   中英

Property 'cat' does not exist on type

I have a problem, in the portion of code below:

getPorts() {
let brands = [];

this.vehicles.forEach(country => {
  country.brands.forEach(brand => {
    brand.cat = country ;
    brands.push(brand);
  });
});
console.log(brands);
this.brands = brands;
} 

the error is :

Property 'cat' does not exist on type '{ 'brand': string; 'flag': string; }'.

how to resolve this problem.

her's a portion of data which i use:

{
  'cat': 'A',
  'brands': [
    {
      'brand': 'Adamoli','flag':'https://restcountries.eu/data/ita.svg'
    },

  ]
},

Maybe one of the brands does not have a property 'cat'.

It's difficult to answer this without seeing your data model. Can you console.log out "this.vehicles".

It looks like the portion of data is the "country", which contains the "cat". But you're trying to get "cat" from the "brand" which doesn't contain that property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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