Skip to content

Commit

Permalink
test: add extra typescript test coverage for UUID schematype
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 2, 2022
1 parent 0b78e82 commit 243e4d4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,25 @@ function gh12431() {
expectType<{ testDate?: Date, testDecimal?: Types.Decimal128 }>({} as Example);
}

function gh12593() {
async function gh12593() {
const testSchema = new Schema({ x: { type: Schema.Types.UUID } });

type Example = InferSchemaType<typeof testSchema>;
expectType<{ x?: Buffer }>({} as Example);

const Test = model('Test', testSchema);

const doc = await Test.findOne({ x: '4709e6d9-61fd-435e-b594-d748eb196d8f' }).orFail();
expectType<Buffer | undefined>(doc.x);

const doc2 = new Test({ x: '4709e6d9-61fd-435e-b594-d748eb196d8f' });
expectType<Buffer | undefined>(doc2.x);

const doc3 = await Test.findOne({}).orFail().lean();
expectType<Buffer | undefined>(doc3.x);

const arrSchema = new Schema({ arr: [{ type: Schema.Types.UUID }] });

type ExampleArr = InferSchemaType<typeof arrSchema>;
expectType<{ arr: Buffer[] }>({} as ExampleArr);
}

0 comments on commit 243e4d4

Please sign in to comment.