Generic Schema Type in TypeScript
I have a function:
I want to make it generic to handle any schema (or struct schema?) But what is the typescript type of a generic schema?
export const validateRegistrationForm = <Data>(data: Data) => {
const result = S.decodeUnknownEither(RegistrationFormStruct, {
errors: "all",
})(data);
if (Either.isLeft(result)) {
const schemaErrors = ArrayFormatter.formatErrorSync(result.left);
const errors = schemaErrors.reduce(
(acc, error) => {
const fieldKey = error.path.join(".") as keyof Data;
acc[fieldKey] = error.message;
return acc;
},
{} as Record<keyof Data, string>,
);
return [errors, undefined];
}
return [undefined, result.right];
};export const validateRegistrationForm = <Data>(data: Data) => {
const result = S.decodeUnknownEither(RegistrationFormStruct, {
errors: "all",
})(data);
if (Either.isLeft(result)) {
const schemaErrors = ArrayFormatter.formatErrorSync(result.left);
const errors = schemaErrors.reduce(
(acc, error) => {
const fieldKey = error.path.join(".") as keyof Data;
acc[fieldKey] = error.message;
return acc;
},
{} as Record<keyof Data, string>,
);
return [errors, undefined];
}
return [undefined, result.right];
};I want to make it generic to handle any schema (or struct schema?) But what is the typescript type of a generic schema?
