Skip to content

Commit 047c204

Browse files
committed
Define overloading function types
1 parent c111346 commit 047c204

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/annotations/validation/NotEmpty.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ import {addAttributeOptions} from "../../services/models";
44
/**
55
* Don't allow empty strings
66
*/
7-
export function NotEmpty({msg}: {msg?: string}): Function {
7+
export function NotEmpty(target: any, propertyName: string): void;
8+
export function NotEmpty(options: {msg: string}): Function;
9+
export function NotEmpty(...args: any[]): void|Function {
810

9-
let options: boolean | {msg: string};
10-
11-
if (msg) {
12-
options = {msg};
11+
if (args.length === 1) {
12+
13+
const options = args[0];
14+
15+
return (target: any, propertyName: string) =>
16+
addAttributeOptions(target, propertyName, {
17+
validate: {
18+
notEmpty: options,
19+
}
20+
});
1321
} else {
14-
options = true;
15-
}
16-
17-
return (target: any, propertyName: string) => {
22+
23+
const target = args[0];
24+
const propertyName = args[1];
25+
1826
addAttributeOptions(target, propertyName, {
1927
validate: {
20-
notEmpty: options
28+
notEmpty: true
2129
}
2230
});
2331
}

0 commit comments

Comments
 (0)