Skip to content

Commit

Permalink
Merge 3d17f12 into 62418a1
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 12, 2018
2 parents 62418a1 + 3d17f12 commit d48a062
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/check/arbitrary/RecordArbitrary.ts
Expand Up @@ -11,6 +11,18 @@ export interface RecordConstraints {
with_deleted_keys?: boolean;
}

interface DeletedKeys {
withDeletedKeys: true;
}

interface DeletedKeysDepreciated {
with_deleted_keys: true;
}

type ConstrainedArbitrary<T, Constraints> = Constraints extends DeletedKeys | DeletedKeysDepreciated
? Arbitrary<Partial<T>>
: Arbitrary<T>;

/** @hidden */
function rawRecord<T>(recordModel: { [K in keyof T]: Arbitrary<T[K]> }): Arbitrary<{ [K in keyof T]: T[K] }> {
const keys = Object.keys(recordModel);
Expand Down Expand Up @@ -46,10 +58,10 @@ function record<T>(recordModel: { [K in keyof T]: Arbitrary<T[K]> }): Arbitrary<
* @param recordModel Schema of the record
* @param constraints Contraints on the generated record
*/
function record<T>(
function record<T, Constraints extends RecordConstraints>(
recordModel: { [K in keyof T]: Arbitrary<T[K]> },
constraints: RecordConstraints
): Arbitrary<Partial<{ [K in keyof T]: T[K] }>>;
constraints: Constraints
): ConstrainedArbitrary<{ [K in keyof T]: T[K] }, Constraints>;
function record<T>(recordModel: { [K in keyof T]: Arbitrary<T[K]> }, constraints?: RecordConstraints) {
if (constraints == null || (constraints.withDeletedKeys !== true && constraints.with_deleted_keys !== true))
return rawRecord(recordModel);
Expand Down

0 comments on commit d48a062

Please sign in to comment.