Skip to content

discriminateEntryValue

Applies a predicate to an object entry value and narrows the tuple type when the predicate is a type guard.

Interactive example

Syntax

Classic signature

typescript
function discriminateEntryValue<
  GenericEntry extends readonly [string, unknown],
  GenericPredicateEntryValue extends GenericEntry[1]
>(
  entry: GenericEntry,
  thePredicate: (input: GenericEntry[1]) => input is GenericPredicateEntryValue
): entry is Extract<CleanObjectEntry<GenericEntry>, [string, GenericPredicateEntryValue]>;

Curried signature

typescript
function discriminateEntryValue<
  GenericEntry extends readonly [string, unknown],
  GenericPredicateEntryValue extends GenericEntry[1]
>(
  thePredicate: (input: GenericEntry[1]) => input is GenericPredicateEntryValue
): (entry: GenericEntry) => entry is Extract<CleanObjectEntry<GenericEntry>, [string, GenericPredicateEntryValue]>;

Parameters

  • entry: Key-value tuple to inspect.
  • thePredicate: Predicate applied to the second tuple item, the value.

Return value

A boolean. When thePredicate is a type guard, the result also narrows the tuple type to entries whose value matches the predicate.

See also

Released under the MIT license.