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

158
Views
TypeScript either or return type is not detecting properties
type MyReturnType = Promise<boolean> | void

interface TestInterface {
    testFunction(): MyReturnType;
}

class TestClass implements TestInterface {
    testFunction() {
    }
}

const testObject = new TestClass();
testObject.testFunction()
    .then(() => { });

Why does it through the following error?

Property 'then' does not exist on type 'void'.

Am I missing something?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you use the Union Type (denoted by the pipe character, '|'), you cannot assume the testFunction will return one type or another.

First you must check what type the testFunction returns after it has been called.

const result = testObject.testFunction()
if (result instanceof Promise) {
    result.then(() => {});
}
about 4 years ago · Juan Pablo Isaza 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!