Skip to content

Commit c0ccd19

Browse files
committed
feat: Support readonly options for Types.string and Types.number
1 parent 1b82cfc commit c0ccd19

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/__tests__/types.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,23 @@ describe('types', () => {
155155
expectType<typeof value>(undefined);
156156
});
157157

158-
test('options', () => {
159-
types.number({
158+
test('options, range and modulo', () => {
159+
const options = {
160160
maximum: 9,
161161
minimum: 2,
162162
multipleOf: 2,
163-
});
163+
} as const;
164+
types.number(options);
165+
166+
// @ts-expect-error invalid option
167+
types.number({ maxLength: 1 });
168+
});
169+
170+
test('options, enum', () => {
171+
const options = {
172+
enum: [1, 2, 3],
173+
} as const;
174+
types.number(options);
164175

165176
// @ts-expect-error invalid option
166177
types.number({ maxLength: 1 });
@@ -306,11 +317,12 @@ describe('types', () => {
306317
});
307318

308319
test('options', () => {
309-
types.string({
320+
const options = {
310321
enum: ['foo', 'bar'],
311322
maxLength: 9,
312323
minLength: 1,
313-
});
324+
} as const;
325+
types.string(options);
314326

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

src/types.ts

Lines changed: 2 additions & 2 deletions
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)