Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
Is there a type for things that are instance of Object?

I'm writing a little type guarding tool, and am trying to come up with a way to split every possible type into a few types that cover every possible type, making sure there's no overlap.

I know in JavaScript primitive types are a thing, so maybe I could start with primitive and non-primitive types. Primitives are string, number, bigint, boolean, symbol, null and undefined, so I can define a type guard like:

type Primitive = string | number | bigint | boolean | symbol | undefined | null;

function isPrimitive(val: unknown): val is Primitive {
    return typeof val === 'string' 
        || typeof val === 'number' 
        || typeof val === 'bigint' 
        || typeof val === 'boolean' 
        || typeof val === 'symbol' 
        || val === undefined 
        || val === null;
}

Now I want the complement of that. On the JavaScript side, I know typeof val === 'object' won't help because that'd include null. But val instanceof Object seems to work. It returns false for everything isPrimitive returns true, and it seems to return true for everything else:

function isNotPrimitive(val: unknown): val is Object {
    return val instanceof Object;
}

The problem is that val is Object is broader than what the function returns because the TypeScript Object type seems to include primitives:

type NumberIsObject = number extends Object ? 'Yes' : 'No'; // "Yes"

So is there a type in TypeScript that corresponds to things that are instances of Object? Or if not, is there a better way to group types into broad categories that will satisfy my criteria?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda