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

435
Views
Agregar método personalizado a Object.prototype en TypeScript

Tengo el siguiente código:

 Object.prototype.custom = function() {
 return this
}

Funciona bien en JavaScript, pero cuando lo pongo en TypeScript, aparece este error:

 Property 'custom' does not exist on type 'Object'.ts(2339)

¿Cómo puedo eludir o resolver esta queja?

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Por el bien del experimento (no recomendado en producción, IMO), puede ignore o extender Object (también conocido como aumento)

 // @ts-ignore
Object.prototype.custom = function() {
 return this
}

interface Object {
 custom2(): Object;
}

Object.prototype.custom2 = function() {
 return this
}

parque infantil TS

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