Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/types/ValidationStrategy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import type { ValidatorFunction } from './ValidatorFunction';

export type ValidationStrategy<T extends Record<string, unknown>> = {
[Prop in keyof T]: ValidatorFunction<T[Prop], T> | ValidatorFunction<T[Prop], T>[];
[Prop in keyof T]: ValidatorFunction | ValidatorFunction[];
};
2 changes: 1 addition & 1 deletion src/types/Validator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import type { ValidationStrategy } from './ValidationStrategy';
import type { ValidatorFunction } from './ValidatorFunction';

export type Validator<T extends Record<string, unknown>> = {
validate: ValidationStrategy<T>;
validate: ValidationStrategy<Partial<T>>;
};
4 changes: 4 additions & 0 deletions tests/Validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,17 @@ test('[Validators] ValidateNested correctly validates a deeply nested property',

test('[Validators] ValidateNested correctly validates a value that is not an object', (t) => {
const value = 'test';

//@ts-expect-error
const validator = ValidateNested({ key: 'test' });

t.throws(() => validator(value, 'test-property'));
});

test('[Validators] ValidateNested correctly validates a value that is an empty object', (t) => {
const value = {};

//@ts-expect-error
const validator = ValidateNested({ key: 'test' });

t.throws(() => validator(value, 'test-property'));
Expand Down