Skip to content

Commit b902701

Browse files
committed
docs: add signature especially for the api docs
1 parent 66b2f2e commit b902701

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/random.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ export class Random {
179179
object: T,
180180
field?: unknown
181181
): T[K];
182+
/**
183+
* Returns a random key or value from given object.
184+
*
185+
* @template T The type of `Record` to pick from.
186+
* @template K The keys of `T`.
187+
* @param object The object to get the keys or values from.
188+
* @param field If this is set to `'key'`, this method will a return a random key of the given instance.
189+
* If this is set to `'value'`, this method will a return a random value of the given instance.
190+
* Defaults to `'value'`.
191+
*
192+
* @example
193+
* const object = { keyA: 'valueA', keyB: 42 };
194+
* faker.random.objectElement(object) // 42
195+
* faker.random.objectElement(object, 'key') // 'keyB'
196+
* faker.random.objectElement(object, 'value') // 'valueA'
197+
*/
198+
objectElement<T extends Record<string, unknown>, K extends keyof T>(
199+
object: T,
200+
field?: 'key' | 'value'
201+
): K | T[K];
182202
objectElement<T extends Record<string, unknown>, K extends keyof T>(
183203
object = { foo: 'bar', too: 'car' } as unknown as T,
184204
field = 'value'

0 commit comments

Comments
 (0)