ts-data-forge
    Preparing search index...
    • Creates a new record that contains only the specified keys from the source record. This function supports both direct usage and curried form for functional composition.

      Type Safety: Only keys that exist in the source record type are allowed, preventing runtime errors from accessing non-existent properties.

      Type Parameters

      • const R extends UnknownRecord

        The type of the input record

      • const Keys extends readonly (keyof R)[]

        The readonly array type of keys to pick from the record

      Parameters

      • record: R

        The source record to pick properties from

      • keys: Keys

        A readonly array of keys to include in the result

      Returns Pick<R, ArrayElement<Keys>>

      A new record containing only the specified keys and their values

      const user = {
      id: 1,
      name: 'Bob',
      email: 'bob@example.com',
      password: 'secret',
      role: 'admin',
      };

      // Direct usage
      const publicInfo = Obj.pick(user, ['id', 'name', 'role']);

      assert.deepStrictEqual(publicInfo, {
      id: 1,
      name: 'Bob',
      role: 'admin',
      });

      // Curried usage with pipe
      const nameAndEmail = pipe(user).map(Obj.pick(['name', 'email'])).value;

      assert.deepStrictEqual(nameAndEmail, {
      name: 'Bob',
      email: 'bob@example.com',
      });
    • Creates a new record that contains only the specified keys from the source record. This function supports both direct usage and curried form for functional composition.

      Type Safety: Only keys that exist in the source record type are allowed, preventing runtime errors from accessing non-existent properties.

      Type Parameters

      • const Keys extends readonly PropertyKey[]

        The readonly array type of keys to pick from the record

      Parameters

      • keys: Keys

        A readonly array of keys to include in the result

      Returns <const R extends UnknownRecord>(record: R) => RelaxedPick<R, ArrayElement<Keys>>

      A new record containing only the specified keys and their values

      const user = {
      id: 1,
      name: 'Bob',
      email: 'bob@example.com',
      password: 'secret',
      role: 'admin',
      };

      // Direct usage
      const publicInfo = Obj.pick(user, ['id', 'name', 'role']);

      assert.deepStrictEqual(publicInfo, {
      id: 1,
      name: 'Bob',
      role: 'admin',
      });

      // Curried usage with pipe
      const nameAndEmail = pipe(user).map(Obj.pick(['name', 'email'])).value;

      assert.deepStrictEqual(nameAndEmail, {
      name: 'Bob',
      email: 'bob@example.com',
      });