@luolapeikko/ts-common
    Preparing search index...

    Function propEquals

    • Creates a predicate function that checks whether a given object's property equals the specified value.

      Supports both strictly typed object structures and looser records with optional properties.

      Useful for filtering arrays of objects based on property values.

      Type Parameters

      • T extends Record<PropertyKey, any>

        The object type with known keys (strict overload).

      • K extends string | number | symbol

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: T[K]

        The value to match against.

      Returns (obj: T) => boolean

      A predicate for use with arrays of type T.

      // Strict object structure
      const isAdmin = propEquals<User, 'role'>('role', 'admin');
      const admins = users.filter(isAdmin);
      // Loosely typed object
      const isPublished = propEquals('status', 'published');
      const publishedPosts = posts.filter(isPublished);

      v0.4.2

    • Creates a predicate function that checks whether a given object's property equals the specified value.

      Supports both strictly typed object structures and looser records with optional properties.

      Useful for filtering arrays of objects based on property values.

      Type Parameters

      • V

        The value type of the property (loose overload).

      • K extends PropertyKey

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: V

        The value to match against.

      Returns (obj: Partial<Record<K, V>>) => boolean

      A predicate for use with arrays of type T.

      // Strict object structure
      const isAdmin = propEquals<User, 'role'>('role', 'admin');
      const admins = users.filter(isAdmin);
      // Loosely typed object
      const isPublished = propEquals('status', 'published');
      const publishedPosts = posts.filter(isPublished);

      v0.4.2