diff --git a/lib/models/Model.d.ts b/lib/models/Model.d.ts index a1b89a03..d081836a 100644 --- a/lib/models/Model.d.ts +++ b/lib/models/Model.d.ts @@ -24,6 +24,18 @@ import {ICountOptions} from '../interfaces/ICountOptions'; type ForTypeOf = {[P in keyof T]: T[P]}; type NonAbstractTypeOfModel = (new () => T) & ForTypeOf; +type Diff = ({[P in T]: P} & {[P in U]: never} & {[x: string]: never})[T]; +type Omit = {[P in Diff]: T[P]}; + +type GetAttributes> = + Partial>> | { + id?: number|any; + createdAt?: Date|any; + updatedAt?: Date|any; + deletedAt?: Date|any; + version?: number|any; +}; + export declare abstract class Model extends Hooks { constructor(values?: any, options?: IBuildOptions); @@ -293,29 +305,29 @@ export declare abstract class Model extends Hooks { /** * Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty. */ - static build>(this: (new () => T), record?: any, options?: IBuildOptions): T; + static build>(this: (new () => T), record?: GetAttributes, options?: IBuildOptions): T; static build, A>(this: (new () => T), record?: A, options?: IBuildOptions): T; /** * Undocumented bulkBuild */ - static bulkBuild>(this: (new () => T), records: any[], options?: IBuildOptions): T[]; + static bulkBuild>(this: (new () => T), records: GetAttributes[], options?: IBuildOptions): T[]; static bulkBuild, A>(this: (new () => T), records: A[], options?: IBuildOptions): T[]; /** * Builds a new model instance and calls save on it. */ - static create>(this: (new () => T), values?: any, options?: ICreateOptions): Promise; + static create>(this: (new () => T), values?: GetAttributes, options?: ICreateOptions): Promise; static create, A>(this: (new () => T), values?: A, options?: ICreateOptions): Promise; /** * Find a row that matches the query, or build (but don't save) the row if none is found. * The successfull result of the promise will be (instance, initialized) - Make sure to use .spread() */ - static findOrInitialize>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; + static findOrInitialize>(this: (new () => T), options: IFindOrInitializeOptions>): Promise<[T, boolean]>; static findOrInitialize, A>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; - static findOrBuild>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; + static findOrBuild>(this: (new () => T), options: IFindOrInitializeOptions>): Promise<[T, boolean]>; static findOrBuild, A>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; /** @@ -329,14 +341,14 @@ export declare abstract class Model extends Hooks { * an instance of sequelize.TimeoutError will be thrown instead. If a transaction is created, a savepoint * will be created instead, and any unique constraint violation will be handled internally. */ - static findOrCreate>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; + static findOrCreate>(this: (new () => T), options: IFindOrInitializeOptions>): Promise<[T, boolean]>; static findOrCreate, A>(this: (new () => T), options: IFindOrInitializeOptions): Promise<[T, boolean]>; /** * A more performant findOrCreate that will not work under a transaction (at least not in postgres) * Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again */ - static findCreateFind>(this: (new () => T), options: IFindCreateFindOptions): Promise<[T, boolean]>; + static findCreateFind>(this: (new () => T), options: IFindCreateFindOptions>): Promise<[T, boolean]>; static findCreateFind, A>(this: (new () => T), options: IFindCreateFindOptions): Promise<[T, boolean]>; /** @@ -373,7 +385,7 @@ export declare abstract class Model extends Hooks { * * @param records List of objects (key/value pairs) to create instances from */ - static bulkCreate>(this: (new () => T), records: any[], options?: BulkCreateOptions): Promise; + static bulkCreate>(this: (new () => T), records: GetAttributes[], options?: BulkCreateOptions): Promise; static bulkCreate, A>(this: (new () => T), records: A[], options?: BulkCreateOptions): Promise; /** @@ -398,7 +410,7 @@ export declare abstract class Model extends Hooks { * elements. The first element is always the number of affected rows, while the second element is the actual * affected rows (only supported in postgres with `options.returning` true.) */ - static update>(this: (new () => T), values: any, options: UpdateOptions): Promise<[number, Array]>; + static update>(this: (new () => T), values: GetAttributes, options: UpdateOptions): Promise<[number, Array]>; static update, A>(this: (new () => T), values: A, options: UpdateOptions): Promise<[number, Array]>; /** * Run a describe query on the table. The result will be return to the listener as a hash of attributes and