diff --git a/src/__tests__/types.test.ts b/src/__tests__/types.test.ts index 85b20776e..1926ce634 100644 --- a/src/__tests__/types.test.ts +++ b/src/__tests__/types.test.ts @@ -166,12 +166,23 @@ describe('types', () => { }); }); - test('options', () => { - types.number({ + test('options, range and modulo', () => { + const options = { maximum: 9, minimum: 2, multipleOf: 2, - }); + } as const; + types.number(options); + + // @ts-expect-error invalid option + types.number({ maxLength: 1 }); + }); + + test('options, enum', () => { + const options = { + enum: [1, 2, 3], + } as const; + types.number(options); // @ts-expect-error invalid option types.number({ maxLength: 1 }); @@ -327,11 +338,12 @@ describe('types', () => { }); test('options', () => { - types.string({ + const options = { enum: ['foo', 'bar'], maxLength: 9, minLength: 1, - }); + } as const; + types.string(options); // @ts-expect-error invalid option types.string({ maximum: 1 }); diff --git a/src/types.ts b/src/types.ts index 7a98543a4..0a36e616a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ interface ArrayOptions extends GenericOptions { } interface NumberOptions extends GenericOptions { - enum?: number[]; + enum?: readonly number[]; exclusiveMaximum?: boolean; exclusiveMinimum?: boolean; maximum?: number; @@ -35,7 +35,7 @@ interface ObjectOptions extends GenericOptions { } interface StringOptions extends GenericOptions { - enum?: string[]; + enum?: readonly string[]; maxLength?: number; minLength?: number; pattern?: string;