An interface does not define an initial value for actual objects, but defines the requirements an object must meet for it to be an implementation of that interface.

You should create a factory of some kind that creates objects of type Article, this could be as simple as this function:

const emptyArticle = (): Article => ({
    slug: '',
    title: '',
    description: '',
    body: '',
    tagList: [],
});

You could additionally create a function that accepts an object that is a Partial<Article> - as described here. This enables you to pass a subset of initial values to the function. This example uses emptyArticle defined above:

const createArticle = <T extends Partial<Article>>(initialValues: T): Article & T => {
    return Object.assign(emptyArticle(), initialValues);
};

// Initialize a new article with a certain slug:
createArticle({ slug: 'my-awesome-article' });
Answer from JJWesterkamp on Stack Overflow
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-empty-interface
no-empty-interface | typescript-eslint
An empty interface in TypeScript does very little: any non-nullable value is assignable to {}. Using an empty interface is often a sign of programmer error, such as misunderstanding the concept of {} or forgetting to fill in fields.
Discussions

Add exactly empty object ({} literal) type
Suggestion Add an empty object ({} literal) type 🔍 Search Terms empty interface object type react ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking change in existing TypeScript/JavaScript code This ... More on github.com
🌐 github.com
9
January 20, 2021
Empty interface allow any object?
If interface define what properties object can have, A case should result in error, a is not defined in interface. Non empty interface defines both what object can and must have. More on github.com
🌐 github.com
7
March 12, 2017
How should a variable initialized to empty object be assigned an interface before it is returned?
I wouldn't use as ConfigData because it's a lie. You can easily forget one of the properties and compiler won't warn you. I would build properties first and then just return { prop1, prop2, prop3 } without initializing return obj at all. More on reddit.com
🌐 r/typescript
12
15
June 8, 2020
typescript - Empty interface allow any object? - Stack Overflow
Empty interface doesn't define any constraint and is applicable to any object. I'm not sure about its utility though. ... This behavior is intentional. The excess property check is not performed when the target is an empty object type since it is rarely the intent to only allow empty objects. Actually, you can assign {a: 1} to B, the other answers here are mostly wrong. You have stumbled upon another slightly confusing quirk in TypeScript... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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?

🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-interface-empty-object
How to initialize a typed Empty Object in TypeScript | bobbyhadz
The {[key: string]: any} syntax is an index signature in TypeScript and is used when we don't know all the names of a type's properties and the shape of the values ahead of time. The index signature in the examples means that when an object is indexed with a string, it will return a value of any type. You can also use the Record utility type to initialize a typed empty object. ... Copied!interface Employee { id: number; name: string; } const emp1: Employee | Record<string, never> = {};
🌐
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.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 42426
Add exactly empty object ({} literal) type · Issue #42426 · microsoft/TypeScript
January 20, 2021 - Right now, TypeScript does not have a way to define a {} literal type, because {} is an object with no properties and all non-nullish values have at least no properties https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-all-types-assignable-to-empty-interfaces
Author   emiliskiskis
🌐
Tim Mousk
timmousk.com › blog › typescript-empty-object
How To Initialize An Empty Typed Object In TypeScript? – Tim Mouskhelichvili
March 2, 2023 - The weakness of this method is that you need to transform an object into a class each time. Also, with newer versions of TypeScript, you need to initialize each property. Another option to initialize an empty typed object is to use the TypeScript partial utility type.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 14606
Empty interface allow any object? · Issue #14606 · microsoft/TypeScript
March 12, 2017 - If interface define what properties object can have, A case should result in error, a is not defined in interface. Non empty interface defines both what object can and must have.
Author   mleko
Find elsewhere
🌐
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 {}.
🌐
Patricemgoma
patricemgoma.com › how-to-create-an-empty-object-from-an-interface-in-typescript
How to create an empty object from an interface in Typescript ? - Patrice M Goma
September 30, 2020 - To instantiate an empty object you can use this syntaxe : ... A Typical use of this is when you want to create a new record. Here in angular we create a new company record and pass it to a service that can send the data to a Web API for example. export interface ICompany { companyId: number; name: string; address: string; zipCode: string; creationDate: string ; } import { CompanyService } from '../company.service'; import { ICompany } from '../interfaces/company'; import {Router} from '@angular/router' ; import * as moment from 'moment'; @Component({ selector: 'app-create-company', templateUrl
🌐
Reddit
reddit.com › r/typescript › how should a variable initialized to empty object be assigned an interface before it is returned?
r/typescript on Reddit: How should a variable initialized to empty object be assigned an interface before it is returned?
June 8, 2020 -
export default interface ConfigData {
   languageCode : string
   , numberOfRepeats : number
}

Probably a basic thing for you guys to sort out. I'm thinking on initialization, allow TS to infer variable type, then enforce the interface as return type:

   run() {
      // data to be returned at end
      const configData = {};

      this.steps.forEach(async (configStep: WizardSteps): ConfigData => {
         // capture answer
         const rawUserResponse: string|void = await configStep.explain();

         if (configStep.needsValidation) {
            // loops until validated
            const validatedInput: string = configStep.validatedInput(rawUserResponse);
            
            if (configStep.hasSaveableData) { 
               // convert to k/v pair
               const formattedForConfiguration = configStep.format(rawUserResponse);

               // save to local object
               Object.assign(configData, formattedForConfiguration);
            }
         }
      })

      return configData;
   }

Is this the proper pattern? If not, how should an interface enforce types on something that is initially set to one value and then mutated?

Top answer
1 of 4
10

This behavior is intentional.

The excess property check is not performed when the target is an empty object type since it is rarely the intent to only allow empty objects.


Actually, you can assign {a: 1} to B, the other answers here are mostly wrong.

You have stumbled upon another slightly confusing quirk in TypeScript, namely that you can not directly assign an object literal to a type where the object literal contains other properties than the one specified in the type.

However, you can assign any existing instance of an object to a type, as long as it fulfill the type.

For example:

interface Animal {
    LegCount: number;
}

let dog: Animal = { LegCount: 4, Fur: "Brown" }; // Nope

var myCat = { LegCount: 4, Fur: "Black" };
let theCat: Animal = myCat; // OK

This constraint is simply ignored whey you have a type that is empty.

Read more here and here.

A later answer from the Typescript team is available on GitHub.

2 of 4
3

Okay, interesting question.

Test Case 1:

interface A {};
interface B extends A {
    b?: any;
}
const a: A = {a: 1};
console.log(a);

It passes, as A is an empty interface, whatever you dumb inside is going to return back. Works like a class Object

Test Case 2:

interface A {};
interface B extends A {
    b?: any;
}
const a: A = {b: 1};
console.log(a);

Just changed the value a to b just to prove first test case. It passes.

Test Case 3:

interface A {};
interface B extends A {
    b?: any;
}
const a: B = {a: 1};
console.log(a);

It fails, because there is no prop inside interface A or B that is named a

Test Case 4:

interface A {};
interface B extends A {
    b?: any;
}
const a: B = {b: 1};
console.log(a);

It passes, as interface B has a prop named b

I hope this helps you understand.

PS: prop refers to property.

Take this as an analogy: Interface A is a empty house, dumb whatever you want. It wont utter a word. Interface B is a house in a colony, which means it needs behave specifically to size, shape and needs to stick to Interface A. Which means Interface B is not more a empty and is restricted with rules.

🌐
GitHub
github.com › Microsoft › TypeScript › issues › 8032
Empty object or type (`{} | Type`) doesn't work as expected · Issue #8032 · microsoft/TypeScript
December 4, 2016 - Empty object or type ({} | Type) doesn't work as expected#8032 · Copy link · Labels · QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code · alexgorbatchev · opened · on Apr 12, 2016 · Issue body actions · 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 = {}; Expected behavior: Should be able to assign cat.legs or {} interchangeably.
Author   alexgorbatchev
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-empty-object-type
no-empty-object-type | typescript-eslint
Whether to allow empty object type literals. Default: "never". ... A stringified regular expression to allow interfaces and object type aliases with the configured name.
🌐
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 - What Is the Empty Object {} Type in TypeScript? Here’s why you need to use a special type of Record instead of {} to represent empty objects in TypeScript. TypeScript’s type system is great …
🌐
SonarSource
rules.sonarsource.com › typescript › rspec-4023
TypeScript static code analysis
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your TYPESCRIPT code
🌐
GitHub
github.com › bobbyhadz › typescript-interface-empty-object
GitHub - bobbyhadz/typescript-interface-empty-object: A repository for an article at https://bobbyhadz.com/blog/typescript-interface-empty-object
Alternatively, you can run the TypeScript project in watch mode, so that the TypeScript server is restarted every time you make a change and save.
Author   bobbyhadz
🌐
Oxidation Compiler
oxc.rs › docs › guide › usage › linter › rules › typescript › no-empty-object-type
typescript/no-empty-object-type Restriction
This can be useful if your existing code style includes a pattern of declaring empty types with {} instead of object. Example of incorrect code for this rule with { allowWithName: 'Props$' }: ts · interface InterfaceValue {} type TypeValue = {}; Example of correct code for this rule with { allowWithName: 'Props$' }: ts · interface InterfaceProps {} type TypeProps = {}; To enable this rule using the config file or in the CLI, you can use: Config (.oxlintrc.json)Config (oxlint.config.ts)CLI · json · { "rules": { "typescript/no-empty-object-type": "error" } } ts ·
🌐
Webdevtutor
webdevtutor.net › blog › typescript-empty-interface-object
Understanding TypeScript Empty Interface Object
When working with TypeScript, empty interface objects can be a useful tool for creating flexible type definitions. An empty interface in TypeScript is a way to define an object type that has no properties.