From 63f8b3b3232cba979f84698b70dcd3177253ee9f Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 10 May 2018 10:19:15 -0700 Subject: [PATCH] Fix typescript definitions to be compatible with LB4 --- types/datasource.d.ts | 4 +++- types/model.d.ts | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/types/datasource.d.ts b/types/datasource.d.ts index 382f4cbf..35ac5a20 100644 --- a/types/datasource.d.ts +++ b/types/datasource.d.ts @@ -83,7 +83,9 @@ export declare class DataSource { DataAccessObject: AnyObject & {prototype: AnyObject}; - constructor(name?: string, settings?: Options, modelBuilder?: ModelBuilder); + constructor(name: string, settings?: Options, modelBuilder?: ModelBuilder); + + constructor(settings?: Options, modelBuilder?: ModelBuilder); constructor( connectorModule: Connector, diff --git a/types/model.d.ts b/types/model.d.ts index 97743b69..dc12c48b 100644 --- a/types/model.d.ts +++ b/types/model.d.ts @@ -92,7 +92,7 @@ export declare class ModelDefinition extends EventEmitter implements Schema { } /** - * Base model class + * Base class for LoopBack 3.x models */ export declare class ModelBase { static dataSource?: DataSource; @@ -135,15 +135,16 @@ export declare class ModelBase { static getUpdateOnlyProperties(): string[]; /** - * Model class: base class for all persistent objects. + * Constructor for ModelBase * - * `ModelBaseClass` mixes `Validatable` and `Hookable` classes methods + * NOTE: We have to use `constructor(...args: any[]);` so that it can be used + * for `return class extends superClass`. * - * @class * @param {AnyObject} data Initial object data * @param {Options} options An object to control the instantiation */ - constructor(data: AnyObject, options?: Options); + constructor(...args: any[]); + // constructor(data: AnyObject, options?: Options); /** * Convert the model instance to a plain json object @@ -160,20 +161,17 @@ export declare class ModelBase { * Convert model instance to a plain JSON object. * Returns a canonical object representation (no getters and setters). * - * @param {boolean} onlySchema Restrict properties to dataSource only. + * @param options Options for the conversion + * @property {boolean} onlySchema Restrict properties to dataSource only. * Default is false. If true, the function returns only properties defined * in the schema; Otherwise it returns all enumerable properties. - * @param {boolean} removeHidden Boolean flag as part of the transformation. + * @property {boolean} removeHidden Boolean flag as part of the transformation. * If true, then hidden properties should not be brought out. - * @param {boolean} removeProtected Boolean flag as part of the transformation. + * @property {boolean} removeProtected Boolean flag as part of the transformation. * If true, then protected properties should not be brought out. * @returns {object} returns Plain JSON object */ - toObject( - onlySchema?: boolean, - removeHidden?: boolean, - removeProtected?: boolean, - ): AnyObject; + toObject(options?: Options): AnyObject; /** * Define a property on the model.