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

229
Views
¿Por qué mi interfaz de TypeScript no me alerta de que le faltan algunas propiedades?

Tengo una interfaz TypeScript con las propiedades requeridas.

Pero al escribir un objeto y colocarlo en una matriz, no aparece ningún mensaje de error que me alerte de que faltan algunas de las propiedades requeridas.

Aquí hay un ejemplo de mi código:

 interface Keyword { keyword: string; language: string; location: string; searchEngineDomain: string; organicPositionLastThirtyDays: number[]; createdAt: string; } const keywords = []; keywords.push({ keyword: 'My First Keyword', } as Keyword);

Esperaba ver un error que me dijera que al objeto que estoy insertando en la matriz le faltan cinco propiedades requeridas. Pero no veo ningún error en absoluto.

¿Por qué pasó esto?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es porque las keywords son del tipo any[] , mientras que deberían ser Keyword[] . También debe eliminar as Keyword , ya que significa "créanme, es todo lo que queremos aquí". Las aserciones de tipo pueden ocultar errores de tipo.

Echa un vistazo al siguiente fragmento:

 interface Keyword { keyword: string; language: string; location: string; searchEngineDomain: string; organicPositionLastThirtyDays: number[]; createdAt: string; } const keywords: Keyword[] = []; keywords.push({ keyword: 'My First Keyword', });

Recibirá el siguiente error:

Argumento de tipo '{ palabra clave: cadena; }' no se puede asignar a un parámetro de tipo 'Palabra clave'. Escriba '{ palabra clave: cadena; }' faltan las siguientes propiedades del tipo 'Palabra clave': idioma, ubicación, searchEngineDomain, organicPositionLastThirtyDays, createdAt

about 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!