UNPKG

@thinman/ts-factory

Version:

TypeScript factories for generating fixtures, with custom constructor support. No docs yet, sorry.

20 lines (19 loc) 1.26 kB
export declare type AttributeFn<T> = () => Partial<T>; export declare type ConstructorParameterFn<T extends AnyConstructor> = () => ConstructorParameters<T>; export declare type AnyConstructor = { new (...args: any[]): any; }; export declare class ClassFactory<T extends AnyConstructor> { extraAttributes?: AttributeFn<InstanceType<T>> | Partial<InstanceType<T>>; constructorParams?: ConstructorParameterFn<T> | ConstructorParameters<T>; clazz: T; constructor(clazz: T, constructorParameterFn?: ConstructorParameterFn<T> | ConstructorParameters<T>, attributeCreatorFn?: AttributeFn<InstanceType<T>> | Partial<InstanceType<T>>); private parseFnOrValue; generate: (attributeOverrides?: AttributeFn<InstanceType<T>> | Partial<InstanceType<T>> | undefined) => InstanceType<T>; generateMany: (howMany: number, attributeOverrides?: AttributeFn<InstanceType<T>> | Partial<InstanceType<T>> | undefined) => Array<T>; extend: (options: ClassFactoryExtendOptions<T>) => ClassFactory<T>; } export interface ClassFactoryExtendOptions<T extends AnyConstructor> { constructorParams?: ConstructorParameterFn<T> | ConstructorParameters<T>; extraAttributes?: AttributeFn<InstanceType<T>> | Partial<InstanceType<T>>; }