Caveats

Here are two worthy caveats from the comments.

Either you want user to be of type User | {} or Partial<User>, or you need to redefine the User type to 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. In this example, the property Username is left undefined, while the type annotation is saying it can't be undefined. – Ian Liu Rodrigues

Answer

One of the design goals of TypeScript is to "strike a balance between correctness and productivity." If it will be productive for you to do this, use Type Assertions to create empty objects for typed variables.

type User = {
    Username: string;
    Email: string;
}

const user01 = {} as User;
const user02 = <User>{};

user01.Email = "[email protected]";

Here is a working example for you.

Answer from Shaun Luttin on Stack Overflow
🌐
Reddit
reddit.com › r/typescript › how to declare empty object in typescript?
r/typescript on Reddit: How to declare empty object in TypeScript?
September 12, 2021 -

I know this is a really basic question, and I've tried to look at similar questions and didn't understand it so I apologize.

I'm translating my JavaScript code to TypeScript, and have a lot of code that looks similar to this:

	if (!user_dict.options) {
		user_dict.options = {}
	}

This produces the error "property options does not exist on type {}" for both lines. How can I establish an empty object like this, if I don't know what type of variables will later be stored? I have hundreds of empty variable declarations like this, and I can't know at this point in the code the "type" of variable being stored later, so I don't understand how I'm supposed to handle this using TypeScript?

Discussions

Initialize empty object in typescript with Record type - Stack Overflow
How to define and initialize an object that can be empty. With types type Plan = 'plan1' | 'plan1'; interface IPlan { name: string } When I tried to initialize an empty object, I'm getting an ... 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
Define an empty object type in TypeScript - Stack Overflow
There are several options for defining an empty object type, and it completely depends on the side-effects you want regarding your linter and typescript errors when accessing or setting properties. More on stackoverflow.com
🌐 stackoverflow.com
How can I create an object based on an interface file definition in TypeScript? - Stack Overflow
0 Form not displaying with empty form fields as part of the create CRUD process in Angular 7 application · 0 Create Object and add Values in Typescript Cannot set property 'X' of undefined More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...
🌐
Total TypeScript
totaltypescript.com › the-empty-object-type-in-typescript
The Empty Object Type in TypeScript | Total TypeScript
April 2, 2024 - So this behaves in exactly the same way. So you shouldn't be using this Object type either. # If you do want to represent a kind of empty object, then we can use this Record<PropertyKey, never>.
🌐
Execute Program
executeprogram.com › courses › everyday-typescript › lessons › the-empty-object-type
Everyday TypeScript: The Empty Object Type
Welcome to the The Empty Object Type lesson! This lesson is shown as static text below. However, it's designed to be used interactively. 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 {}.
🌐
Tim Mousk
timmousk.com › blog › typescript-empty-object
How To Initialize An Empty Typed Object In TypeScript? – Tim Mouskhelichvili
March 2, 2023 - This article explains different methods to initialize an empty typed object in TypeScript with code examples.
🌐
Codú
codu.co › home › feed › niall maher › how to type empty objects in typescript
How to Type Empty Objects in TypeScript | by Niall Maher | Codú
July 21, 2023 - type EmptyObject = {}; // ✅ Passes the Type check: const test1: EmptyObject = "This is a test"; // ✅ Passes the Type check: const test2: EmptyObject = {}; // ✅ Passes the Type check: const test3: EmptyObject = { test: "Yes, I work too...", ...
🌐
Medium
raihankabir862.medium.com › how-to-define-a-proper-type-for-an-empty-object-in-typescript-with-the-help-of-generic-a936a69859af
How to define a proper type for an empty object in Typescript with the help of Generics | by Raihan kabir | Medium
January 6, 2024 - I have observed many developers creating type with the help of index signatures like this: type IObjectInitializer = { [key: string]: any; }; In the above code, what it does is define a type for an object that can have any key of type string, and the values can be of any type, which essentially breaks the fundamental principles of TypeScript.
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-interface-empty-object
How to initialize a typed Empty Object in TypeScript | bobbyhadz
Use a type assertion to initialize a typed empty object in TypeScript. You can then set the properties on the object using dot or bracket notation.
🌐
Frontend Masters
frontendmasters.com › courses › intermediate-typescript-v2 › object-empty-objects
object & Empty Objects - Intermediate TypeScript, v2 | Frontend Masters
[00:05:55] So we create val2 which is of type empty object. It accepts four, it accepts a string, it accepts a date. It accepts a string or number. Here's a nullable string. And I'm gonna do, TypeScript again getting super clever here.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 47486
Empty object type is not working · Issue #47486 · microsoft/TypeScript
January 18, 2022 - 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 ...
Author   Asaf-S
🌐
Webdevtutor
webdevtutor.net › blog › typescript-empty-object-of-type
Creating TypeScript Empty Object of Type
One way to create an empty object of a specific type in TypeScript is to use type assertion.
Top answer
1 of 16
762

If you are creating the "modal" variable elsewhere, and want to tell TypeScript it will all be done, you would use:

declare const modal: IModal;

If you want to create a variable that will actually be an instance of IModal in TypeScript you will need to define it fully.

const modal: IModal = {
    content: '',
    form: '',
    href: '',
    $form: null,
    $message: null,
    $modal: null,
    $submits: null
};

Or lie, with a type assertion, but you'll lost type safety as you will now get undefined in unexpected places, and possibly runtime errors, when accessing modal.content and so on (properties that the contract says will be there).

const modal = {} as IModal;

Example Class

class Modal implements IModal {
    content: string;
    form: string;
    href: string;
    $form: JQuery;
    $message: JQuery;
    $modal: JQuery;
    $submits: JQuery;
}

const modal = new Modal();

You may think "hey that's really a duplication of the interface" - and you are correct. If the Modal class is the only implementation of the IModal interface you may want to delete the interface altogether and use...

const modal: Modal = new Modal();

Rather than

const modal: IModal = new Modal();
2 of 16
284

If you want an empty object of an interface, you can do just:

var modal = <IModal>{};

The advantage of using interfaces in lieu of classes for structuring data is that if you don't have any methods on the class, it will show in compiled JS as an empty method. Example:

class TestClass {
    a: number;
    b: string;
    c: boolean;
}

compiles into

var TestClass = (function () {
    function TestClass() {
    }
    return TestClass;
})();

which carries no value. Interfaces, on the other hand, don't show up in JS at all while still providing the benefits of data structuring and type checking.

🌐
Webdevtutor
webdevtutor.net › blog › typescript-make-empty-object
How to Create an Empty Object in TypeScript
In this blog post, we have explored different methods to create an empty object in TypeScript. Whether you prefer the literal syntax, Object.create method, or type assertion, you can choose the method that best fits your use case.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › create
Object.create() - JavaScript - MDN Web Docs
o = {}; // Is equivalent to: o = Object.create(Object.prototype); o = Object.create(Object.prototype, { // foo is a regular data property foo: { writable: true, configurable: true, value: "hello", }, // bar is an accessor property bar: { configurable: false, get() { return 10; }, set(value) { console.log("Setting `o.bar` to", value); }, }, }); // Create a new object whose prototype is a new, empty // object and add a single property 'p', with value 42....
🌐
DhiWise
dhiwise.com › blog › design-converter › typescript-empty-object-guide-best-practices
Understanding the TypeScript Empty Object
March 3, 2025 - The way TypeScript handles empty objects depends on type rules, object literals, and assignable values.
🌐
GitHub
github.com › Microsoft › TypeScript › issues › 8032
Empty object or type (`{} | Type`) doesn't work as expected · Issue #8032 · microsoft/TypeScript
December 4, 2016 - TypeScript Version: 1.8.9 Code 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