import type {EmptyObject} from 'type-fest';
// The following illustrates the problem with `{}`.
const foo1: {} = {}; // Pass
const foo2: {} = []; // Pass
const foo3: {} = 42; // Pass
const foo4: {} = {a: 1}; // Pass
// With `EmptyObject` only the first case is valid.
const bar1: EmptyObject = {}; // Pass
const bar2: EmptyObject = 42; // Fail
const bar3: EmptyObject = []; // Fail
const bar4: EmptyObject = {a: 1}; // Fail
Unfortunately, Record<string, never>
, Record<keyof any, never>
and Record<never, never>
do not work. See #395.
Represents a strictly empty plain object, the
{}
value.When you annotate something as the type
{}
, it can be anything exceptnull
andundefined
. This means that you cannot use{}
to represent an empty plain object (read more).