Skip to content

Commit

Permalink
Update to strongly typed
Browse files Browse the repository at this point in the history
  • Loading branch information
Opender Singh committed Oct 14, 2019
1 parent 8c39351 commit 6b4c0c8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ type InternalSchema<T> = {
};

const fromSchema = <T>(schema: Schema<T>): T => {
const result: T = {} as any;
const result: Partial<T> = {};

for (const key in schema) {
if (schema.hasOwnProperty(key)) {
result[key] = schema[key]();
}
}

return result;
return result as T;
};

type Mutator<T> = {
Expand All @@ -38,17 +38,19 @@ export class FluentBuilder<T extends object> {
public constructor(schema: Schema<T>) {
this.schema = schema;
this.internalSchema = {...schema};
this.mutator = {} as any;
const mutator: Partial<Mutator<T>> = {};

for (const key in this.internalSchema) {
if (this.internalSchema.hasOwnProperty(key)) {
this.mutator[key] = ((v: T[typeof key]) => {
mutator[key] = ((v: T[typeof key]) => {
this.internalSchema[key] = init(v);

return this.mutator;
}) as Mutate<T, typeof key>;
}
}

this.mutator = mutator as Mutator<T>;
}

public mutate = (func: (mutate: Mutator<T>) => void): FluentBuilder<T> => {
Expand Down

0 comments on commit 6b4c0c8

Please sign in to comment.