Type alias NotEmpty<Type>

NotEmpty<Type>: Exclude<Type, Empty>

Type for a non-empty ArrayLike, object or string.

Remarks

This type is useful for cases where you want to ensure that a value is not empty. For example, if you have an array that should always have at least one element, you could type it as NotEmpty<ArrayLike<ElementType>>.

Example

const notEmptyString: NotEmpty<string> = "🟢";
const notEmptyArray: NotEmpty<ReadOnlyArray> = ["🟢", "🟩"];
const notEmptyRecord: NotEmpty<ReadOnlyRecord> = { "🟢": "🟩" };

See

Empty

Type Parameters

  • Type extends ArrayLike | object | string

    The type to check.