Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Define and Use an Empty Object Type in TypeScript

TypeScript has no general sealed type for an object with zero properties. Choose `{}`, `object`, `unknown`, or a named type according to the constraint you need—and validate actual emptiness at runtime.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

TypeScript has no general type that guarantees a value has exactly zero properties. In particular, {} does not mean “empty object”: with strictNullChecks enabled, it accepts any non-nullish value, including primitives. Choose a type for the constraint you actually need, and validate at runtime if the absence of properties matters.

What does {} mean in TypeScript?

With strictNullChecks enabled, {} accepts any value other than null or undefined. That includes strings, numbers, booleans, and objects. It does not require a value to be an object, much less an object with no properties.

const text: {} = "hello";
const value: {} = { extra: true };

The TypeScript project FAQ explains that because TypeScript has no sealed or closed types, there is no type that refers to values with zero properties: TypeScript FAQ: “Primitives are {}, and {} Doesn’t Mean object”. With strictNullChecks disabled, nullability behavior differs, so avoid treating the examples above as configuration-independent. The Handbook recommends enabling strict null checking: TypeScript Handbook: Basic Types.

Which type should you use instead?

Start with the intended constraint. These types are not interchangeable: {} concerns nullish values, object excludes primitives, and unknown is for values not yet inspected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Starting type What it permits or requires
Any non-nullish value {} Primitives and objects; not null or undefined when strictNullChecks is enabled. It does not mean empty.
Any non-primitive value object Objects, arrays, and functions; does not prohibit properties. TypeScript Handbook
Arbitrary input that has not been inspected unknown Any value, including nullish values; narrow it before using it as a specific type. TypeScript Handbook
A known configuration or data shape A named object type or interface Declares the properties the program expects; structural typing does not generally forbid additional properties. TypeScript Handbook: Object Types
No own enumerable string-keyed properties at runtime Runtime validation Check the actual value and decide whether symbols, non-enumerable properties, or inherited keys count as “empty.”

How do you type a known object shape?

If the value has a meaningful shape, describe that shape instead of trying to express a universal empty object. Optional properties allow callers to omit a property; they do not create a sealed type that rejects every additional property in every assignment context.

type Options = {
  mode?: "fast" | "safe";
};

const options: Options = { mode: "fast" };

TypeScript can report an excess-property error when a fresh object literal includes a property not declared by the target type. This is a useful typo check, not a general exact-object guarantee: other values and assignment routes can still carry additional properties. See the Handbook’s discussion of excess property checks.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Why not use Record<string, never>?

Record<Keys, Type> is a mapped utility type for giving a selected set of keys a value type; it is useful for dictionary-like types. It is not a general switch for sealed, exact objects. The TypeScript FAQ specifically rejects using this kind of Record as a way to express its non-nullish-value meaning. See TypeScript Handbook: Utility Types and the TypeScript FAQ.

How can you check that a value is empty at runtime?

First define “empty” for your application. The following helper checks that a value is a non-null object and has no own enumerable string-keyed properties:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function hasNoEnumerableStringKeys(value: unknown): boolean {
  return typeof value === "object" &&
    value !== null &&
    Object.keys(value).length === 0;
}

Object.keys does not count symbol keys, non-enumerable properties, or inherited properties. If any of those should make a value non-empty, use a validation rule that checks them too. This is runtime validation of a concrete value, not a compile-time guarantee about every value assignable to a type.

For untrusted input, accepting unknown and then narrowing is safer than claiming it already has a particular object shape:

function inspect(value: unknown) {
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
    // The value is object-like; its properties are not yet known.
  }
}
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What about unconstrained generic types?

Older TypeScript code may rely on an unconstrained generic parameter behaving as though it had an implicit {} constraint. TypeScript 3.5 changed unconstrained generic parameters to use unknown instead. That change reflects the distinction between an arbitrary value and a value known to satisfy a narrower constraint. See the TypeScript breaking changes for 3.5.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.