diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts index 616226ee522..159ad84833d 100644 --- a/scripts/apidoc/directMethods.ts +++ b/scripts/apidoc/directMethods.ts @@ -41,8 +41,9 @@ export function processDirectMethod( methodName.substring(0, 1).toUpperCase() + methodName.substring(1); console.log(`Processing Direct: ${upperMethodName}`); - const signature = (direct.type as TypeDoc.ReflectionType).declaration - .signatures[0]; + const signatures = (direct.type as TypeDoc.ReflectionType).declaration + .signatures; + const signature = signatures[signatures.length - 1]; writeApiDocsDirectPage(methodName); writeApiDocsData(methodName, [ diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts index 89c42a33a56..7b090d13e9c 100644 --- a/scripts/apidoc/moduleMethods.ts +++ b/scripts/apidoc/moduleMethods.ts @@ -50,7 +50,8 @@ function processModuleMethod(module: TypeDoc.DeclarationReflection): PageIndex { )) { const methodName = method.name; console.debug(`- ${methodName}`); - const signature = method.signatures[0]; + const signatures = method.signatures; + const signature = signatures[signatures.length - 1]; methods.push(analyzeSignature(signature, lowerModuleName, methodName)); } diff --git a/src/random.ts b/src/random.ts index 47720de2b6b..c2d8ecb2bb4 100644 --- a/src/random.ts +++ b/src/random.ts @@ -179,6 +179,26 @@ export class Random { object: T, field?: unknown ): T[K]; + /** + * Returns a random key or value from given object. + * + * @template T The type of `Record` to pick from. + * @template K The keys of `T`. + * @param object The object to get the keys or values from. + * @param field If this is set to `'key'`, this method will a return a random key of the given instance. + * If this is set to `'value'`, this method will a return a random value of the given instance. + * Defaults to `'value'`. + * + * @example + * const object = { keyA: 'valueA', keyB: 42 }; + * faker.random.objectElement(object) // 42 + * faker.random.objectElement(object, 'key') // 'keyB' + * faker.random.objectElement(object, 'value') // 'valueA' + */ + objectElement, K extends keyof T>( + object: T, + field?: 'key' | 'value' + ): K | T[K]; objectElement, K extends keyof T>( object = { foo: 'bar', too: 'car' } as unknown as T, field = 'value'