Skip to content

truthy

The truthy() function is a type guard that keeps only truthy values (false, 0, "", null, undefined are excluded).

Interactive example

Syntax

typescript
function truthy<
	GenericInput extends unknown,
>(
	input: GenericInput
): input is TruthyValue<GenericInput>;

Parameters

  • input: Value to test.

Return value

A type guard that is true when input is truthy.

See also

  • falsy - Keep only falsy values
  • isType - Runtime type guard

Released under the MIT license.