Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda