Skip to content

Commit

Permalink
fix(index.d.ts): allow using type: SchemaDefinitionProperty in sche…
Browse files Browse the repository at this point in the history
…ma definitions

Re: #10605
Re: #7181
  • Loading branch information
vkarpov15 committed Aug 25, 2021
1 parent 5d1a64b commit d862a5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ declare module 'mongoose' {
T extends number[] ? (SchemaDefinitionWithBuiltInClass<number>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<number>>) :
T extends boolean[] ? (SchemaDefinitionWithBuiltInClass<boolean>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<boolean>>) :
T extends Function[] ? (SchemaDefinitionWithBuiltInClass<Function>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<Function>>) :
T | typeof SchemaType | Schema<any, any, any>;
T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T>;

/** Defines a virtual with the given name that gets/sets this path. */
alias?: string;
Expand Down
1 change: 1 addition & 0 deletions test/typescript/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Test.find({ parent: '0'.repeat(24) });

// Operators
Test.find({ name: { $in: ['Test'] } }).exec().then((res: Array<ITest>) => console.log(res));
Test.find({ tags: 'test' }).exec();

Test.find({ name: 'test' }, (err: Error, docs: ITest[]) => {
console.log(!!err, docs[0].age);
Expand Down
19 changes: 19 additions & 0 deletions test/typescript/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,23 @@ function gh10409() {
const someSchema = new Schema<Something, Model<Something>, Something>({
field: { type: Date }
});
}

function gh10605() {
interface ITest {
arrayField?: string[];
object: {
value: number
};
}
const schema = new Schema<ITest>({
arrayField: [String],
object: {
type: {
value: {
type: Number
}
}
}
});
}

0 comments on commit d862a5a

Please sign in to comment.