aboutsummaryrefslogtreecommitdiff
path: root/src/checkable.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/checkable.ts')
-rw-r--r--src/checkable.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/checkable.ts b/src/checkable.ts
index 89d0c7150..b6ef49fac 100644
--- a/src/checkable.ts
+++ b/src/checkable.ts
@@ -156,6 +156,25 @@ export namespace Checkable {
}
+ export function ClassWithValidator(target: any) {
+ target.checked = (v: any) => {
+ let cv = checkValue(v, {
+ propertyKey: "(root)",
+ type: target,
+ checker: checkValue
+ }, ["(root)"]);
+ let instance = new target();
+ if (typeof instance.validate !== "function") {
+ throw Error("invalid Checkable annotion: validate method required");
+ }
+ // May throw exception
+ instance.validate.call(cv);
+ return cv;
+ };
+ return target;
+ }
+
+
export function Value(type: any) {
if (!type) {
throw Error("Type does not exist yet (wrong order of definitions?)");
@@ -259,4 +278,4 @@ export namespace Checkable {
}
return chk;
}
-} \ No newline at end of file
+}