Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions types/rosie/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ declare namespace rosie {
attr<K extends keyof T, D1 extends keyof T, D2 extends keyof T>(name: K, dependencies: [D1, D2], generatorFunction: (value1: T[D1], value2: T[D2]) => T[K]): IFactory<T>;
attr<K extends keyof T, D extends keyof T>(name: K, dependencies: D[], generatorFunction: (value: T[D]) => T[K]): IFactory<T>;
attr<K extends keyof T, D extends keyof T>(name: K, dependencies: D[], generatorFunction: any): IFactory<T>;
attr<K extends keyof T>(name: K, dependencies: string[], generatorFunction: (...dependencies: any[]) => T[K]): IFactory<T>;

/**
* Convenience function for defining a set of attributes on this object as
Expand Down
14 changes: 14 additions & 0 deletions types/rosie/rosie-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ const person = Factory.build<Person>('Person');
let aString = '';
aString = person.firstName;

// It supports options not defined in the type definition
const personWithNicknameFactory = new Factory<Person>()
.attr('firstName', 'Frances')
.attr('lastName', 'Parker')
.option('nickname', null)
.attr('fullName', ['firstName', 'lastName', 'nickname'], (firstName, lastName, nickname) => {
if (nickname) {
return `${firstName} "${nickname}" ${lastName}`;
}
return `${firstName} ${lastName}`;
});
// $ExpectType Person
const personWithNickname = personWithNicknameFactory.build({}, { nickname: 'Franny' });

// Unregistered factories
const unregisteredPersonFactory = new Factory<Person>();

Expand Down