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

114
Views
Typescript type guard without returning

Let's say I want to have

const isNotNull = (object: any) => {
  if (isNull && obj === null) {
    throw new Error('object is null');
  }
}

const obj: null | object = getObject();
isNotNull(obj);
// now I want to enforce that object is no longer null

How do I do this? Type guards work only if your function isNotNull returns something. I want to infer the type without having my function return anything.

I now want this someAssertion to do a type guard, but to be dynamic

about 4 years ago · Juan Pablo Isaza
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!