Skip to content

Commit

Permalink
feat: Allow const enums (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers authored Jul 11, 2023
1 parent 3958e77 commit 194e505
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum TEST_ENUM {
FOO = 'foo',
BAR = 'bar',
}
const READONLY_CONST_VALUES = ['qux', 'baz'] as const;

describe('schema', () => {
test('simple', () => {
Expand Down Expand Up @@ -465,6 +466,7 @@ describe('schema', () => {
decimalOptional: types.decimal(),
decimalRequired: types.decimal({ required: true }),
enumOptional: types.enum([...Object.values(TEST_ENUM), null]),
enumReadonly: types.enum(READONLY_CONST_VALUES),
enumRequired: types.enum(Object.values(TEST_ENUM), { required: true }),
nullOptional: types.null(),
nullRequired: types.null({ required: true }),
Expand Down Expand Up @@ -596,6 +598,9 @@ describe('schema', () => {
enumOptional: {
enum: ['foo', 'bar', null],
},
enumReadonly: {
enum: ['qux', 'baz'],
},
enumRequired: {
enum: ['foo', 'bar'],
},
Expand Down Expand Up @@ -736,6 +741,7 @@ describe('schema', () => {
decimalOptional?: Decimal128;
decimalRequired: Decimal128;
enumOptional?: TEST_ENUM | null;
enumReadonly?: 'qux' | 'baz';
enumRequired: TEST_ENUM;
nullOptional?: null;
nullRequired: null;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function constant<Value, Options extends GenericOptions>(
}

function enumType<Enum, Options extends GenericOptions>(
values: Enum[],
values: readonly Enum[],
options?: Options
): GetType<Enum, Options> {
return {
Expand Down

0 comments on commit 194e505

Please sign in to comment.