Skip to content

Commit

Permalink
fix: blueprint builder methods for optional properties are typed as p…
Browse files Browse the repository at this point in the history
…ossibly undefined
  • Loading branch information
luchsamapparat committed Sep 18, 2019
1 parent 650a6cd commit c6b42cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/blueprint.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ describe('createBlueprintBuilder', () => {
interface Product {
name: string;
price: number;
rating?: number;
}

const productBlueprint: Blueprint<Product> = {
name: () => commerce.productName(),
price: () => random.number({ min: 0.01, max: 99.99, precision: 0.01 })
price: () => random.number({ min: 0.01, max: 99.99, precision: 0.01 }),
rating: () => random.number({ min: 1, max: 5 })
};

const productBlueprintFn: BlueprintFactory<Product> = () => productBlueprint;
Expand All @@ -25,6 +27,7 @@ describe('createBlueprintBuilder', () => {
const altName = commerce.productName();
const altPrice = random.number({ min: 0.01, max: 99.99, precision: 0.01 });
const betterAltPrice = multiply(altPrice, multiplicand);
const altRating = random.number({ min: 1, max: 5 });


it('returns a builder that uses the given blueprint to create a new value', () => {
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('createBlueprintBuilder', () => {
const product = productBuilder()
.name(altName)
.price(altPrice)
.rating(altRating)
.build();

expect(product.name).toBe(altName);
Expand Down
2 changes: 1 addition & 1 deletion src/blueprint.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type BlueprintBuilder<T> = Builder<T> & BlueprintBuilderMethods<T>;
export type BlueprintBuilderMethod<V, T> = (value: V) => BlueprintBuilder<T>;

export type BlueprintBuilderMethods<T> = {
[P in keyof T]: BlueprintBuilderMethod<T[P], T>;
[P in keyof Required<T>]: BlueprintBuilderMethod<T[P], T>;
};

export function createBlueprintBuilder<T>(blueprintFn: Blueprint<T> | BlueprintFactory<T>): (values?: Partial<T>) => BlueprintBuilder<T> {
Expand Down

0 comments on commit c6b42cf

Please sign in to comment.