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

242
Views
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
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!