Skip to content

emptyObjectTypes

Reports empty object type literals and empty interfaces that are often used incorrectly.

✅ This rule is included in the ts logical and logicalStrict presets.

The {} (“empty object”) type in TypeScript is a common source of confusion. It actually represents any non-nullish value, not an empty object. This includes primitives like strings and numbers.

Similarly, an empty interface interface Foo {} is equivalent to {}.

If you want to represent any object, use object. If you want any value, use unknown.

AEty53 EmptA53 {<};d ivclassNa="meco"><};d>AEinterfa53 Empty <{}d ivclassNa="meco"><{}d>AEle53val7<2:sp ansty="le--0:#C792EA;--1:#8844">AE <{}sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0f1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53par7<2:sp ansty="le--0:#D6DEEB;--1:#403F">53 <{}sp ansty="le--0:#D9F5DD;--1:#1111">1<1)sp ansty="le--0:#D6DEEB;--1:#403F">53 <{}d ivclassNa="meco"><{}d>
44AE3F53 HasMemb4<4AE= spans="tyle--0:#D6DEEB;--1:#40">3F53 {< foo spans="tyle--0:#7FDBCA;--1:#09">6361B0st3F5<3 } ;divclass="Name"><;di vdivclass="Nameexpressive-">44AEinter3F53 HasMembe3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F5<3foo spans="tyle--0:#7FDBCA;--1:#09">6361B0st33<}di vdivclass="Nameexpressive-">44AE3F53v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0ob3<;di vdivclass="Nameexpressive-">44AE3F53v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0unk3<;di vdivclass="Nameexpressive-">6376// Empty object in intersection types is allowed (useful for NonNulla44AE3F53 NonNulla1<111T spans="tyle--0:#D6DEEB;--1:#40">3F<53> spans="tyle--0:#C792EA;--1:#88">4 ><4AE= spans="tyle--0:#D6DEEB;--1:#40">31<111T spans="tyle--0:#D6DEEB;--1:#40">363F53< {} ;divclass="Name">< {}><;di vdivclass="Nameexpressive-">6376// Empty interface extending multiple interfaces is all44AEinter3F53 Combi44AEext361B<0Foo spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#C5E478;--1:#3B">61B<0Bar spans="tyle--0:#D6DEEB;--1:#40">3F5<3 { }divclass="Name">

This rule is not configurable.

If your code commonly needs to represent the “any non-nullish value” type, this rule may not be for you. Projects that extensively use type operations such as conditional types and mapped types may benefit from disabling this rule.