diff --git a/src/validation/joi/joi.shared.schemas.ts b/src/validation/joi/joi.shared.schemas.ts index d0f16a5..ac53811 100644 --- a/src/validation/joi/joi.shared.schemas.ts +++ b/src/validation/joi/joi.shared.schemas.ts @@ -4,7 +4,6 @@ import { _stringEnumKeys, _stringEnumValues, BaseDBEntity, - IsoDate, IsoDateTime, NumberEnum, StringEnum, @@ -24,7 +23,7 @@ export const numberSchema = Joi.number() export const numberSchemaTyped = (): NumberSchema => Joi.number() export const integerSchema = Joi.number().integer() export const percentageSchema = Joi.number().integer().min(0).max(100) -export const dateStringSchema = stringSchema.dateString() as StringSchema +export const dateStringSchema = stringSchema.dateString() export const binarySchema = Joi.binary() export const dateObjectSchema = Joi.object().instance(Date) diff --git a/src/validation/joi/string.extensions.test.ts b/src/validation/joi/string.extensions.test.ts index 126de87..2f92cc7 100644 --- a/src/validation/joi/string.extensions.test.ts +++ b/src/validation/joi/string.extensions.test.ts @@ -1,6 +1,9 @@ +import { expectTypeOf } from '@naturalcycles/dev-lib/dist/testing' import { IsoDate, localTime } from '@naturalcycles/js-lib' import { testValidation } from '../../test/validation.test.util' import { stringSchema } from './joi.shared.schemas' +import { validate } from './joi.validation.util' +import { StringSchema } from './string.extensions' test('dateString', () => { const schema = stringSchema.dateString() @@ -15,6 +18,11 @@ test('dateString', () => { test('dateString min/max', async () => { const schema = stringSchema.dateString('2017-06-21' as IsoDate, '2017-06-23' as IsoDate) + expectTypeOf(schema).toEqualTypeOf>() + + const value = validate('2017-06-22' as IsoDate, schema) + expectTypeOf(value).toEqualTypeOf() + testValidation( schema, ['2017-06-21', '2017-06-22', '2017-06-23'], diff --git a/src/validation/joi/string.extensions.ts b/src/validation/joi/string.extensions.ts index 4410de3..7db57f0 100644 --- a/src/validation/joi/string.extensions.ts +++ b/src/validation/joi/string.extensions.ts @@ -3,7 +3,7 @@ import type Joi from 'joi' import { Extension, StringSchema as JoiStringSchema } from 'joi' export interface StringSchema extends JoiStringSchema { - dateString: (min?: IsoDate | 'today', max?: IsoDate | 'today') => this + dateString: (min?: IsoDate | 'today', max?: IsoDate | 'today') => StringSchema } export interface JoiDateStringOptions {