diff --git a/src/__tests__/types.test.ts b/src/__tests__/types.test.ts index a011319e4..d6e8e0d52 100644 --- a/src/__tests__/types.test.ts +++ b/src/__tests__/types.test.ts @@ -168,12 +168,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 }); @@ -329,11 +340,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 e1cdad902..ecaf72598 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,7 +19,7 @@ interface ArrayOptions extends GenericOptions { } interface NumberOptions extends GenericOptions { - enum?: number[]; + enum?: readonly number[]; exclusiveMaximum?: boolean; exclusiveMinimum?: boolean; maximum?: number; @@ -36,7 +36,7 @@ interface ObjectOptions extends GenericOptions { } interface StringOptions extends GenericOptions { - enum?: string[]; + enum?: readonly string[]; maxLength?: number; minLength?: number; pattern?: string;