aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-04-29 16:33:12 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-04-29 16:33:12 -0400
commit661e76a61a13d9a8d925b78e2add0c488611aeec (patch)
tree5fa041b584a180d78dfc2109d75eacec4d0bbace
parent307564d9b02ed9d4de8ffa4229b0494bf8d671bd (diff)
Got rid of some casting
-rw-r--r--src/client/util/SerializationHelper.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/client/util/SerializationHelper.ts b/src/client/util/SerializationHelper.ts
index 1a8cc3a44..b5873eeb3 100644
--- a/src/client/util/SerializationHelper.ts
+++ b/src/client/util/SerializationHelper.ts
@@ -55,18 +55,18 @@ let serializationTypes: { [name: string]: any } = {};
let reverseMap: { [ctor: string]: string } = {};
export interface DeserializableOpts {
- (constructor: Function): void;
+ (constructor: { new(...args: any[]): any }): void;
withFields(fields: string[]): Function;
}
export function Deserializable(name: string): DeserializableOpts;
-export function Deserializable(constructor: Function): void;
-export function Deserializable(constructor: Function | string): DeserializableOpts | void {
- function addToMap(name: string, ctor: Function) {
- const schema = getDefaultModelSchema(ctor as any) as any;
+export function Deserializable(constructor: { new(...args: any[]): any }): void;
+export function Deserializable(constructor: { new(...args: any[]): any } | string): DeserializableOpts | void {
+ function addToMap(name: string, ctor: { new(...args: any[]): any }) {
+ const schema = getDefaultModelSchema(ctor) as any;
if (schema.targetClass !== ctor) {
- const newSchema = { ...schema, factory: () => new (ctor as any)() };
- setDefaultModelSchema(ctor as any, newSchema);
+ const newSchema = { ...schema, factory: () => new ctor() };
+ setDefaultModelSchema(ctor, newSchema);
}
if (!(name in serializationTypes)) {
serializationTypes[name] = ctor;
@@ -76,7 +76,7 @@ export function Deserializable(constructor: Function | string): DeserializableOp
}
}
if (typeof constructor === "string") {
- return Object.assign((ctor: Function) => {
+ return Object.assign((ctor: { new(...args: any[]): any }) => {
addToMap(constructor, ctor);
}, { withFields: Deserializable.withFields });
}