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

233
Views
Programatic way to get list of JS primitive types

Does JS expose a list of primitive types that can be accessed programmatically, or is there a built in method to find out if a string is a type? This is a somewhat contrived language-based question and not intended to solve a specific algorithm.

Besides manually hard-coding array of ['string', 'number', 'boolean', etc...], is there a way to programmatically get that list?

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

0

There is no definitive way to get a list of typeof results built into JavaScript itself.

If they are exposed somewhere, that would be through a library or as part of the API of a specific environment.


In TypeScript you can define a type that covers all possible primitive types as shown in this answer:

const uselessVariable = typeof (1 as any);

// type Test = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
type Test = typeof uselessVariable;

Playground Link

In TypeScript the JavaScript typeof operator is assigned a return type which is restricted to only the results that are possible for it.

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!