Skip to content

Commit

Permalink
fix: type of isValidationErrorResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
airjp73 committed Jun 13, 2024
1 parent 3de22a7 commit 65e9e9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/core/src/createValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ValidationErrorResponseData,
Validator,
} from "./types";
import { GenericObject, preprocessFormData } from "./native-form-data/flatten";
import { preprocessFormData } from "./native-form-data/flatten";
import { FORM_ID_FIELD_NAME } from "./constants";

/**
Expand All @@ -12,7 +12,7 @@ import { FORM_ID_FIELD_NAME } from "./constants";
* extracting the values from FormData.
*/
export function createValidator<T>(
validator: CreateValidatorArg<T>,
validator: CreateValidatorArg<T>
): Validator<T> {
return {
validate: async (value) => {
Expand Down Expand Up @@ -42,6 +42,9 @@ export function createValidator<T>(
};
}

export const isValidationErrorResponse = <T extends GenericObject>(
response: T | ValidationErrorResponseData,
): response is ValidationErrorResponseData => "fieldErrors" in response;
export const isValidationErrorResponse = <T>(
response: T | ValidationErrorResponseData
): response is ValidationErrorResponseData =>
typeof response === "object" &&
response !== null &&
"fieldErrors" in response;
4 changes: 2 additions & 2 deletions packages/remix/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ValidationErrorResponseData, ValidatorError } from "@rvf/core";
export function validationError(
error: ValidatorError,
repopulateFields?: unknown,
init?: ResponseInit,
init?: ResponseInit
) {
return new Response(
JSON.stringify({
Expand All @@ -35,6 +35,6 @@ export function validationError(
headers: {
"Content-Type": "application/json; utf-8",
},
},
}
) as TypedResponse<ValidationErrorResponseData>;
}

0 comments on commit 65e9e9e

Please sign in to comment.