Skip to content

Commit

Permalink
Merge pull request #2703 from pappaschris/improve_validate_typings
Browse files Browse the repository at this point in the history
issue #2606: pass TSchema from ObjectSchema to .validate function
  • Loading branch information
hueniverse committed Dec 1, 2021
2 parents b623dc8 + 5a7a8fa commit e92e400
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,14 @@ declare namespace Joi {

type ValidationErrorFunction = (errors: ErrorReport[]) => string | ValidationErrorItem | Error;

interface ValidationResult {
error?: ValidationError;
type ValidationResult<TSchema = any> = {
error: undefined;
warning?: ValidationError;
value: any;
value: TSchema;
} | {
error: ValidationError;
warning?: ValidationError;
value: undefined;
}

interface CreateErrorOptions {
Expand Down Expand Up @@ -846,7 +850,7 @@ declare namespace Joi {
$_validate(value: any, state: State, prefs: ValidationOptions): ValidationResult;
}

interface AnySchema extends SchemaInternals {
interface AnySchema<TSchema = any> extends SchemaInternals {
/**
* Flags of current schema.
*/
Expand Down Expand Up @@ -1169,7 +1173,7 @@ declare namespace Joi {
/**
* Validates a value using the schema and options.
*/
validate(value: any, options?: ValidationOptions): ValidationResult;
validate(value: any, options?: ValidationOptions): ValidationResult<TSchema>;

/**
* Validates a value using the schema and options.
Expand Down Expand Up @@ -1589,7 +1593,7 @@ declare namespace Joi {
matches: SchemaLike | Reference;
}

interface ObjectSchema<TSchema = any> extends AnySchema {
interface ObjectSchema<TSchema = any> extends AnySchema<TSchema> {
/**
* Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.
*
Expand Down

0 comments on commit e92e400

Please sign in to comment.