Skip to content

Commit

Permalink
support true as validation result
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 25, 2023
1 parent dce1f18 commit 92bb5ef
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/internal/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createError } from "../../error";
// TODO: Consider using similar method of typeschema for external library compatibility
// https://github.com/decs/typeschema/blob/v0.1.3/src/assert.ts

export type ValidateResult<T> = T | false | void;
export type ValidateResult<T> = T | true | false | void;

export type ValidateFunction<T> = (
data: unknown
Expand All @@ -18,6 +18,9 @@ export async function validateData<T>(
if (res === false) {
throw createValidationError();

Check warning on line 19 in src/utils/internal/validate.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/internal/validate.ts#L19

Added line #L19 was not covered by tests
}
if (res === true) {
return data as T;

Check warning on line 22 in src/utils/internal/validate.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/internal/validate.ts#L22

Added line #L22 was not covered by tests
}
return res ?? (data as T);
} catch (error) {
throw createValidationError(error);
Expand Down

0 comments on commit 92bb5ef

Please sign in to comment.