Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Assign a property of nested array inside a new string array

I'm new in VueJs and Typescript, so I have four interfaces:

export interface ShipMethodResponse {
  companyTypeList: CompanyType[]
}

export interface CompanyType {
  companyTypeId: string
  companyTypeName: string
  companyList: Company[]
}

export interface Company {
  companyId: string
  companyTypeId: string
  companyName: string
  companyAbbreviation: string
  companyDescription: string
  companyWebsite: string
  shipMethodList: ShipMethod[]
}

export interface ShipMethod {
  shipMethodId: number
  companyId: string
  shipMethodName: string
}

Each one can have an array of the next interface if you read from top to down.

So I want to insert into a new array of a string the property companyName of Company interface, so I try:

data() {
    return {
      shipMethodList: [] as string[],
      ...
    }
  },

  methods: {

    async myMethod() {
      //companyTypeList is a CompanyType array

      var b = companyTypeList.map((e) => ({
        companyList: e.companyList,
      }))

      for (const c of b) {
        var company = c.companyList.map((company) => ({
          companyName: company.companyName,
        }))

        this.shipMethodList.push(company)
      }


    }
    }

But when I try to push the company it is throwing

Argument of type '{ companyName: string; }[]' is not assignable to parameter of type 'string'.

How can I create a list of all "companyName" property? Regards

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the problem is here:

var company = c.companyList.map((company) => ({
    companyName: company.companyName,
}))

You say you want to create string[], but that map function creates { companyName: string }[]

Change it to this:

var allCompanyNames = c.companyList.map(
    company => company.companyName
)

UPDATE

What you really want is probably this:

for (const c of b) {
    for(company of c.companyList) {
        this.shipMethodList.push(company.companyName)
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda