Struggling with Typescript 2, I am attempting to create a universal parser-method for database objects. Utilizing TypedJSON, I am encountering difficulties in correctly organizing the parameters. Here is part of my code:
private static parseToInstance<T>(dbObject: string, model: T): T {
try {
console.log("parseToInstance()")
let a = TypedJSON.stringify(dbObject);
return TypedJSON.parse(a, new model, "whatever"
} catch (err) {
throw new ParseException(err);
}
}
The method should receive input similar to:
/**
* Converts a JavaScript Object Notation (JSON) string into an instance of the provided class.
* @param text A valid JSON string.
* @param type A class from which an instance is created using the provided JSON string.
* @param settings Per-use serializer settings. Unspecified keys are assigned from global config.
*/
parse<T>(text: string, type: {new (): T;}, settings?: SerializerSettings): T;
An error I am encountering in my code is:
Error:(125, 30) TS2345:Argument of type 'T' is not assignable to parameter of type 'new () => {}'.
Despite attempting multiple solutions, I am unable to resolve this issue. Any assistance would be greatly appreciated.