Skip to content

Commit a2616f4

Browse files
committed
feat: Support readonly options for Types.string and Types.number
1 parent 7fdbe02 commit a2616f4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/__tests__/types.test.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,23 @@ describe('types', () => {
166166
});
167167
});
168168

169-
test('options', () => {
170-
types.number({
169+
test('options, range and modulo', () => {
170+
const options = {
171171
maximum: 9,
172172
minimum: 2,
173173
multipleOf: 2,
174-
});
174+
} as const;
175+
types.number(options);
176+
177+
// @ts-expect-error invalid option
178+
types.number({ maxLength: 1 });
179+
});
180+
181+
test('options, enum', () => {
182+
const options = {
183+
enum: [1, 2, 3],
184+
} as const;
185+
types.number(options);
175186

176187
// @ts-expect-error invalid option
177188
types.number({ maxLength: 1 });
@@ -327,11 +338,12 @@ describe('types', () => {
327338
});
328339

329340
test('options', () => {
330-
types.string({
341+
const options = {
331342
enum: ['foo', 'bar'],
332343
maxLength: 9,
333344
minLength: 1,
334-
});
345+
} as const;
346+
types.string(options);
335347

336348
// @ts-expect-error invalid option
337349
types.string({ maximum: 1 });

src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ArrayOptions extends GenericOptions {
1818
}
1919

2020
interface NumberOptions extends GenericOptions {
21-
enum?: number[];
21+
enum?: readonly number[];
2222
exclusiveMaximum?: boolean;
2323
exclusiveMinimum?: boolean;
2424
maximum?: number;
@@ -35,7 +35,7 @@ interface ObjectOptions extends GenericOptions {
3535
}
3636

3737
interface StringOptions extends GenericOptions {
38-
enum?: string[];
38+
enum?: readonly string[];
3939
maxLength?: number;
4040
minLength?: number;
4141
pattern?: string;

0 commit comments

Comments
 (0)