This is the only solution I can think of (Thanks to the comment of @Fahd Lihidheb)

type NotEmpty<T> = keyof T extends never ? never : T

function createTest<T extends {[key: string]: any}>(test: NotEmpty<T>): T {
  return test
}

const obj = createTest({})                            // error
const anotherObj = createTest({ something: "thing" }) // works

I don't think it is possible with just a type definition. We have to use a factory method instead so we can infer the type of T and check if any keys exist.

Answer from Tobias S. on Stack Overflow
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-empty-object-type
no-empty-object-type | typescript-eslint
In other words, the "empty object" type {} really means "any value that is defined". That includes arrays, class instances, functions, and primitives such as string and symbol. To avoid confusion around the {} type allowing any non-nullish value, ...
🌐
Total TypeScript
totaltypescript.com › the-empty-object-type-in-typescript
The Empty Object Type in TypeScript | Total TypeScript
April 2, 2024 - Instead of representing an empty object, it represents any value except null and undefined. This is because TypeScript's type system is structural, not nominal.
Discussions

Typescript non empty object with unknown properties - Stack Overflow
type NonEmptyObj> = T extends Record ? never : T; This relies on Record which defines an empty object. More on stackoverflow.com
🌐 stackoverflow.com
TypeScript empty object for a typed variable - Stack Overflow
Either you want user to be of type ... allow an empty object. Right now, the compiler is correctly telling you that user is not a User. – jcalz · I don't think this should be considered a proper answer because it creates an inconsistent instance of the type, undermining the whole purpose of TypeScript... More on stackoverflow.com
🌐 stackoverflow.com
Empty object type is not working
Bug Report 🔎 Search Terms Empty object Typescript 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed all of the FAQ's entries. ⏯ Playground Lin... More on github.com
🌐 github.com
12
January 18, 2022
Check if specific object is empty in typescript
The reputation requirement helps ... spam and non-answer activity. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... 1 How to check object property empty value in typescript... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Oxidation Compiler
oxc.rs › docs › guide › usage › linter › rules › typescript › no-empty-object-type
typescript/no-empty-object-type Restriction
The {}, or "empty object" type in TypeScript is a common source of confusion for developers unfamiliar with TypeScript's structural typing. {} represents any non-nullish value, including literals like 0 and "". Often, developers writing {} actually ...
🌐
Mercury
mercury.com › blog › creating-an-emptyobject-type-in-typescript
Creating an EmptyObject type in TypeScript | Mercury
September 19, 2023 - In TypeScript, it is impossible to use the type {} to express “this object should be empty.” Depending on your experience with TypeScript, you may have been frustrated by this before, or you might be surprised that this is a problem worth ...
🌐
Execute Program
executeprogram.com › courses › everyday-typescript › lessons › the-empty-object-type
Everyday TypeScript: The Empty Object Type
Click the button below to start!Start Interactive Lesson · TypeScript allows object types with no properties at all, written as {}. Because of TypeScript's structural typing, we can still pass non-empty objects to a {}.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 47486
Empty object type is not working · Issue #47486 · microsoft/TypeScript
January 18, 2022 - Empty object Typescript · This is the behavior in every version I tried, and I reviewed all of the FAQ's entries. Playground link with relevant code · const emptyObject: Record<string, never> = {}; console.log(emptyObject.id); // Should warn, but doesn't const nonEmptyObject: Record<'a', unknown> = { a: 1 }; console.log(nonEmptyObject.id); // Warning: Property 'id' does not exist on type 'Record<"a", unknown>' I wrapped the Request type of the Express library, in order to change the default value of the Request.params property.
Author   Asaf-S
Find elsewhere
🌐
Palantir
palantir.github.io › tslint › rules › no-inferred-empty-object-type
Rule: no-inferred-empty-object-type
Prior to TypeScript 3.4, generic type parameters for functions and constructors are inferred as {} (the empty object type) by default when no type parameter is explicitly supplied or when the compiler cannot infer a more specific type.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-check-if-object-is-empty
Check if an Object is Empty in TypeScript | bobbyhadz
An alternative approach is to try to iterate over the properties of the object. If there is even a single iteration, then the object is not empty. ... Use a for...in loop to iterate over the properties of the object.
🌐
GitHub
github.com › sindresorhus › type-fest › blob › main › source › non-empty-object.d.ts
type-fest/source/non-empty-object.d.ts at main · sindresorhus/type-fest
This is useful when you need an object where all keys are optional, but there must be at least 1 key. ... export type NonEmptyObject<T extends object> = HasRequiredKeys<T> extends true ?
Author   sindresorhus
🌐
Decipher
decipher.dev › isempty
isEmpty | 30 Seconds of Typescript - Decipher.dev
Returns true if the a value is an empty object, collection, has no enumerable properties or is any type that is not considered a collection. Check if the provided value is null or if its length is equal to 0. ... const isEmpty = (val: any) => ...
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-check-if-an-object-is-empty-in-typescript
How to Check if an Object is Empty in TypeScript ? - GeeksforGeeks
July 23, 2025 - Converting the object into a JSON string allows for easy checking if it's empty by verifying the length of the resulting string. Example: This example shows the use of the above-explained approach. ... const obj7: Record<string, any> = {}; const obj8: Record<string, any> = { language: "TypeScript", version: "4.5" }; if (JSON.stringify(obj7) === '{}') { console.log('obj7 is empty'); } else { console.log('obj7 is not empty'); } if (JSON.stringify(obj8) === '{}') { console.log('obj8 is empty'); } else { console.log('obj8 is not empty'); }
🌐
Medium
medium.com › totally-typescript › what-is-the-empty-object-type-in-typescript-a7c337b399ec
What Is the Empty Object {} Type in TypeScript? | by Dr. Derek Austin 🥳 | Totally TypeScript | Medium
April 30, 2025 - TypeScript’s type system is great, until you realize you have to memorize a bunch of meaningless trivia. Case in point, {} doesn’t actually mean “an empty object” in TypeScript! Instead, it represents “any non-nullish value.” Nullish means “null or undefined” — the same as used in ??, the “nullish coalescing operator.”
🌐
GitHub
github.com › Microsoft › TypeScript › issues › 8032
Empty object or type (`{} | Type`) doesn't work as expected · Issue #8032 · microsoft/TypeScript
December 4, 2016 - interface IAnimal { legs: Number; } interface IHouse { cat: {} | IAnimal; } const obj: IHouse = { cat: { legs: 2, }, }; obj.cat.legs = 5; // Property 'legs' does not exist on type '{} | IAnimal'. obj.cat = {};
Author   alexgorbatchev
🌐
Medium
medium.com › @glasshost › check-if-an-object-is-empty-in-typescript-ba44e236ffe7
Check if an Object is Empty in TypeScript | by Glasshost | Medium
May 2, 2023 - Check if an Object is Empty in TypeScript In TypeScript, it is often necessary to check if an object is empty or not. An empty object is an object that does not have any properties or methods. In …
🌐
Reddit
reddit.com › r/typescript › how to create a type that rejects empty string?
r/typescript on Reddit: How to Create a Type That Rejects Empty String?
December 20, 2023 -

I would like to create a type where it accepts all string except empty string. So buttonAriaLabel = "I am button" is acceptable, but if empty string is passed in buttonAriaLabel = " ", this will generate type error like "empty string is not assignable to type..." . I tried following technique (s: string): s is Excluse<typeof s, ' '> but it doesn't work at all. What are the techniques available to achieve this?

type NonEmptyString = {
  (s: string): s is Exclude<typeof s, ''>;
};
export interface IButton {
  // ... other properties
  buttonAriaLabel: NonEmptyString;
}

// Desired Result
const button: IButton = {
  // ... other properties
  buttonAriaLabel: 'Close', // Valid non-empty string
};
const invalidButton: IButton = {
  // ... other properties
  buttonAriaLabel: '' ", // TypeScript error: Type " " is not assignable to type 'NonEmptyString'.
};

Top answer
1 of 9
44
Even if you can find a way to enforce this with the type system, I would strongly recommend against this. This is a runtime check on the content and not a compile-time one- An empty string is still a string and this is extremely unusual. You’re guaranteed to create confusion down the line. Edit: Clarification- if this is your own personal project- have at it and have fun! If this is for a professional project with other developers, or will be handed off to other developers, this has a high potential for misuse and confusion.
2 of 9
17
IMO, the best way to do this is to use a "branded type" with a constructor function that validates at runtime. This means that anywhere you want to make a NonEmptyString type, you'll have to handle the potential error. declare const opaqueSym: unique symbol; export type NonEmptyString = string & { [opaqueSym]: "NonEmptyString" }; export function NonEmptyString(s: string): NonEmptyString { if (s.length === 0) { throw new Error("NonEmptyString: received an empty string") } return s as NonEmptyString } You could also do a custom type guard: export function isNonEmptyString(s: string): s is NonEmptyString { return s.length > 0; } All that said, this is probably way more effort than necessary when you can just check length at runtime, unless you're composing a bunch of functions that depend on the length being greater than zero. ETA: You can see how a library like Zod can be used to achieve this as well: https://zod.dev/?id=brand And just to restate that last line: the main benefit of using types like this is to make a promise to consuming code that some validation has taken place on a piece of data. It can be useful if you need to mark something as "validated" that might be consumed in many places, and/or if you are validating the same kind of data many times. Another example might be a `DateString` branded type that has been validated to have a certain format.