@types/rosie - make attrs and opts optional for build and buildList (#20462)

* @types/rosie - make attrs and opts optional for build and buildList

* @types/rosie - add 2 tests for build and buildlist param optionality
This commit is contained in:
Bjorn Hougaard
2017-10-10 15:47:53 -04:00
committed by Wesley Wigham
parent 98084c0199
commit 4f052feeaa
2 changed files with 10 additions and 2 deletions

View File

@@ -210,9 +210,9 @@ declare namespace rosie {
* @param {object=} options
* @return {*}
*/
build(attributes: { [k in keyof T]?: T[k] }, options?: any): T;
build(attributes?: { [k in keyof T]?: T[k] }, options?: any): T;
buildList(size: number, attributes: { [k in keyof T]?: T[k] }, options: any): T[];
buildList(size: number, attributes?: { [k in keyof T]?: T[k] }, options?: any): T[];
/**
* Extends a given factory by copying over its attributes, options,

View File

@@ -44,6 +44,14 @@ interface Person {
const personFactory = Factory.define<Person>('Person').attr('firstName', 'John').sequence('id');
// Building does not require the first (attributes) and second (options) arguments
personFactory.build();
personFactory.buildList(3);
// Building with attributes does not require the second (options) argument
personFactory.build({ firstName: "John" });
personFactory.buildList(3, { firstName: "John" });
// It will automatically type up to five dependencies
personFactory.attr('fullName', ['firstName'], firstName => firstName);
personFactory.attr('fullName', ['firstName', 'lastName'], (firstName, lastName) => lastName);