Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

528
Views
Texto mecanografiado: la propiedad no existe en el tipo 'objeto'

Tengo la siguiente configuración y cuando recorro usando for...of y obtengo un error de:

La propiedad "país" no existe en el tipo "objeto".

¿Es esta una forma correcta de recorrer cada objeto en la matriz y comparar el valor de la propiedad del objeto?

 let countryProviders: object[]; export function GetAllProviders() { allProviders = [ { region: "r 1", country: "US", locale: "en-us", company: "co 1" }, { region: "r 2", country: "China", locale: "zh-cn", company: "co 2" }, { region: "r 4", country: "Korea", locale: "ko-kr", company: "co 4" }, { region: "r 5", country: "Japan", locale: "ja-jp", company: "co 5" } ] for (let providers of allProviders) { if (providers.country === "US") { // error here countryProviders.push(providers); } } }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Probablemente también tenga allProviders escritos como object[] . Y la propiedad country no existe sobre el object . Si no le importa escribir, puede declarar allProviders y countryProviders como Array<any> :

 let countryProviders: Array<any>; let allProviders: Array<any>;

Si desea verificar el tipo estático. Puede crear una interfaz para la estructura y usarla:

 interface Provider { region: string, country: string, locale: string, company: string } let countryProviders: Array<Provider>; let allProviders: Array<Provider>;
over 4 years ago · Santiago Trujillo Report

0

Si su objeto pudiera contener cualquier par clave/valor, podría declarar una interfaz llamada keyable como:

 interface keyable { [key: string]: any }

entonces úsalo de la siguiente manera:

 let countryProviders: keyable[];

o

 let countryProviders: Array<keyable>;

Para su caso específico, intente definir el tipo de clave y use la utilidad Record para definir el objeto:

 type ProviderKey="region" | "country" | "locale" | "company" let countryProviders: Array<Record<ProviderKey,string>>;
over 4 years ago · Santiago Trujillo Report

0

Sí, los métodos anteriores son muy recomendables, pero si no tiene otra opción y desea continuar usando "allProviders" como una matriz de objetos, entonces opte por este método. Esto funcionó para mí sin crear una interfaz.

 if(providers["country"] === "US") // replacement
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!