Skip to content

Commit 546947e

Browse files
authored
Merge pull request #271 from spidgorny/master
Fix error on getting type from metadata when no type provided
2 parents 1586ec5 + 0704c63 commit 546947e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/metadata/ParamMetadata.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class ParamMetadata {
102102

103103
constructor(actionMetadata: ActionMetadata, args: ParamMetadataArgs) {
104104
this.actionMetadata = actionMetadata;
105-
105+
106106
this.target = args.object.constructor;
107107
this.method = args.method;
108108
this.extraOptions = args.extraOptions;
@@ -114,7 +114,14 @@ export class ParamMetadata {
114114
this.transform = args.transform;
115115
this.classTransform = args.classTransform;
116116
this.validate = args.validate;
117-
this.targetType = args.explicitType ? args.explicitType : (Reflect as any).getMetadata("design:paramtypes", args.object, args.method)[args.index];
117+
if (args.explicitType) {
118+
this.targetType = args.explicitType
119+
} else {
120+
const metadata = (Reflect as any).getMetadata("design:paramtypes", args.object, args.method);
121+
if (typeof metadata != "undefined") {
122+
this.targetType = metadata[args.index];
123+
}
124+
}
118125

119126
if (this.targetType) {
120127
if (this.targetType instanceof Function && this.targetType.name) {
@@ -127,4 +134,4 @@ export class ParamMetadata {
127134
}
128135
}
129136

130-
}
137+
}

0 commit comments

Comments
 (0)