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

135
Views
isString/Number/ObjectConstructor check in TypeScript

As I knew experimentally, the detecting of the constructor type via switch/case basically works, but sometimes could bring the surprises.

const TYPE: NumberConstructor | StringConstructor | ObjectConstructor = String;

switch(TYPE) {
  case Number: {
    // any applied code
  }
  case String: {
    // any applied code
  }
  case Boolean: {
    // any applied code
  }
}

But how to explore which constructor is TYPE? StringConstructor, NumberConstructor are interfaces and there is no type guards for them.

Please don't touch the TYPE during this topics.

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

0

As @Bergi said, normally the switch/case works fine.

But there could be come special cases like Universal mode in NuxtJS. According @-Ry-, NuxtJS could be bringing in a String constructor from a different execution environment somehow. However, the Stack Overflow rules requires this special case be considered on other question.

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!