Creates a factory function for building objects of a given type. Commonly used to create test objects for use in specs.
interface Message { id: number; text: string;}interface Options { cypherDistance: number;}declare function shiftCharacters(text: string, distance: number): string;const buildMessage = createBuilder<Message, Options>( (seq) => ({ id: seq, text: `message ${seq}` }), (message, _seq, options) => { message.text = shiftCharacters(message.text, options.cypherDistance || 0); },);buildMessage(); // { id: 1, text: "message 1" }buildMessage({ text: "Hello world!" }); // { id: 2, text: "Hello world!" }buildMessage({ text: "abc" }, { cypherDistance: 3 }); // { id: 3, text: "def" } Copy
interface Message { id: number; text: string;}interface Options { cypherDistance: number;}declare function shiftCharacters(text: string, distance: number): string;const buildMessage = createBuilder<Message, Options>( (seq) => ({ id: seq, text: `message ${seq}` }), (message, _seq, options) => { message.text = shiftCharacters(message.text, options.cypherDistance || 0); },);buildMessage(); // { id: 1, text: "message 1" }buildMessage({ text: "Hello world!" }); // { id: 2, text: "Hello world!" }buildMessage({ text: "abc" }, { cypherDistance: 3 }); // { id: 3, text: "def" }
Optional
Creates a factory function for building objects of a given type. Commonly used to create test objects for use in specs.