Hi,
I have a TypeScript class that I want to use in a DataSource for the schema.model property but also for initialising objects that are strongly typed in the rest of my TypeScript code. An example of such a class that seems to work is as follows:
export class Person extends kendo.data.Model.define({ id: "id", fields: { id: { type: "string" }, firstName: { type: "string" }, lastName: { type: "string" }, age: { type: "number" } } }) { id: string; firstName: string; lastName: string; age: number; constructor(id?: string, firstName?: string, lastName?: string, age?: number) { super(); this.id = id; this.firstName = firstName; this.lastName = lastName; this.age = age; }}
However, having the properties defined twice, once for the call to kendo.data.Model.define and then again for the sake of the TypeScript class is not ideal. Is there a better way to do this?
The following would be better if it created the field definitions automatically, but unfortunately it doesn't:
export class Person extends kendo.data.Model { id: string; firstName: string; lastName: string; age: number; constructor(id?: string, firstName?: string, lastName?: string, age?: number) { super(); this.id = id; this.firstName = firstName; this.lastName = lastName; this.age = age; }}
Alternatively, is it possible to move the kendo.data.Model.define() call to inside the constructor?
Thanks
Dean