diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index c65b3bfdd9c..bda45a0582b 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -741,3 +741,14 @@ function pluginOptions() { schema.plugin(pluginFunction2, { option2: 0 }); expectError(schema.plugin(pluginFunction2, {})); // should error because "option2" is not optional } + +function gh12242() { + const dbExample = new Schema( + { + active: { type: Number, enum: [0, 1] as const, required: true } + } + ); + + type Example = InferSchemaType; + expectType<0 | 1>({} as Example['active']); +} diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index 5041f830477..d590b5d65c9 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -156,7 +156,7 @@ type ResolvePathType : PathValueType extends (infer Item)[] ? IfEquals> : ResolvePathType[]> : PathValueType extends StringSchemaDefinition ? PathEnumOrString : - PathValueType extends NumberSchemaDefinition ? number : + PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray ? Options['enum'][number] : number : PathValueType extends DateSchemaDefinition ? Date : PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : PathValueType extends BooleanSchemaDefinition ? boolean :