Skip to content

Commit d93ace5

Browse files
fix(): return a typed schema from create for class method
1 parent 3725961 commit d93ace5

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

lib/factories/schema.factory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { TypeMetadataStorage } from '../storages/type-metadata.storage';
44
import { DefinitionsFactory } from './definitions.factory';
55

66
export class SchemaFactory {
7-
static createForClass<T = any>(target: Type<unknown>) {
7+
static createForClass<T extends Type<unknown> = any>(
8+
target: T,
9+
): mongoose.Schema<mongoose.Document<InstanceType<T>>> {
810
const schemaDefinition = DefinitionsFactory.createForClass(target);
911
const schemaMetadata = TypeMetadataStorage.getSchemaMetadataByTarget(
1012
target,
1113
);
12-
return new mongoose.Schema(
14+
return new mongoose.Schema<mongoose.Document<InstanceType<T>>>(
1315
schemaDefinition,
1416
schemaMetadata && schemaMetadata.options,
1517
);

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"husky": "4.3.5",
3737
"jest": "26.6.3",
3838
"lint-staged": "10.5.3",
39-
"mongoose": "5.11.5",
39+
"mongoose": "^5.11.10",
4040
"prettier": "2.2.1",
4141
"reflect-metadata": "0.1.13",
4242
"release-it": "14.2.2",

0 commit comments

Comments
 (0)