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

292
Views
Extending Promise results in constructor called twice, how come?
class MyPromise<T = void> extends Promise<T> {
  started = false
  resolve: (t: T) => void = () => {}
  reject: (e: any) => void = () => {}
  constructor() {
    console.log('constructor')
    let resolve: (t: T) => void = () => {}
    let reject: (e: any) => void = () => {}
    super((res, rej) => {
      resolve = res
      reject = rej
    })
    this.resolve = resolve
    this.reject = reject
  }
}

const thing = new MyPromise<string>()
thing.resolve('a')
thing.then(t => console.log('then', t))

Constructor is called twice and I get this error

constructor
constructor
[TestError] TypeError: Promise resolve or reject function is not callable

Running on node 14.17.1

about 4 years ago · Santiago Trujillo
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!