Skip to content

Commit ed111ee

Browse files
committed
Make IFindOptions generic
Closes sequelize#161
1 parent cc95b82 commit ed111ee

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

lib/interfaces/IFindCreateFindOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {IFindOptions} from "./IFindOptions";
22

3-
export interface IFindCreateFindOptions<TAttributes> extends IFindOptions {
3+
export interface IFindCreateFindOptions<TAttributes> extends IFindOptions<TAttributes> {
44

55
/**
66
* Default values to use if building a new instance

lib/interfaces/IFindOptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {WhereOptions, LoggingOptions, SearchPathOptions, col, and, or, FindOptionsAttributesArray,
1+
import {WhereOptions, LoggingOptions, SearchPathOptions, col, FindOptionsAttributesArray,
22
literal, fn} from 'sequelize';
33
import {Model} from "../models/Model";
44
import {IIncludeOptions} from "./IIncludeOptions";
55

66
/* tslint:disable:array-type */
77
/* tslint:disable:max-line-length */
88

9-
export interface IFindOptions extends LoggingOptions, SearchPathOptions {
9+
export interface IFindOptions<T> extends LoggingOptions, SearchPathOptions {
1010

1111
/**
1212
* A hash of attributes to describe your search. See above for examples.
1313
*/
14-
where?: WhereOptions<any> | Array<col | and | or | string> | col | and | or | string;
14+
where?: WhereOptions<T>;
1515

1616
/**
1717
* A list of the attributes that you want to select. To rename an attribute, you can pass an array, with

lib/interfaces/IFindOrInitializeOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {IFindOptions} from "./IFindOptions";
22

3-
export interface IFindOrInitializeOptions<TAttributes> extends IFindOptions {
3+
export interface IFindOrInitializeOptions<TAttributes> extends IFindOptions<TAttributes> {
44

55
/**
66
* Default values to use if building a new instance

lib/models/BaseModel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export abstract class BaseModel {
180180
*
181181
* SEE DETAILS FOR ACTUAL FUNCTIONALITY ON DECLARATION FILE
182182
*/
183-
reload(options?: IFindOptions): Promise<this> {
183+
reload(options?: IFindOptions<typeof BaseModel>): Promise<this> {
184184

185185
return parentPrototype.reload.call(this, inferAlias(options, this));
186186
};

lib/models/Model.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export declare abstract class Model<T> extends Hooks {
8181
* @param {Object} [options]
8282
* @param {Boolean} [options.override=false]
8383
*/
84-
static addScope(name: string, scope: IFindOptions | Function, options?: AddScopeOptions): void;
84+
static addScope<T extends Model<T>>(name: string, scope: IFindOptions<T> | Function, options?: AddScopeOptions): void;
8585

8686
/**
8787
* Apply a scope created in `define` to the model. First let's look at how to create scopes:
@@ -194,25 +194,25 @@ export declare abstract class Model<T> extends Hooks {
194194
*
195195
* @see {Sequelize#query}
196196
*/
197-
static findAll<T extends Model<T>>(options?: IFindOptions): Promise<T[]>;
197+
static findAll<T extends Model<T>>(options?: IFindOptions<T>): Promise<T[]>;
198198

199-
static all<T extends Model<T>>(optionz?: IFindOptions): Promise<T[]>;
199+
static all<T extends Model<T>>(options?: IFindOptions<T>): Promise<T[]>;
200200

201201
/**
202202
* Search for a single instance by its primary key. This applies LIMIT 1, so the listener will
203203
* always be called with a single instance.
204204
*/
205-
static findById<T extends Model<T>>(identifier?: number | string, options?: IFindOptions): Promise<T | null>;
205+
static findById<T extends Model<T>>(identifier?: number | string, options?: IFindOptions<T>): Promise<T | null>;
206206

207-
static findByPrimary<T extends Model<T>>(identifier?: number | string, options?: IFindOptions): Promise<T | null>;
207+
static findByPrimary<T extends Model<T>>(identifier?: number | string, options?: IFindOptions<T>): Promise<T | null>;
208208

209209
/**
210210
* Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single
211211
* instance.
212212
*/
213-
static findOne<T extends Model<T>>(options?: IFindOptions): Promise<T | null>;
213+
static findOne<T extends Model<T>>(options?: IFindOptions<T>): Promise<T | null>;
214214

215-
static find<T extends Model<T>>(options?: IFindOptions): Promise<T | null>;
215+
static find<T extends Model<T>>(options?: IFindOptions<T>): Promise<T | null>;
216216

217217
/**
218218
* Run an aggregation method on the specified field
@@ -267,9 +267,9 @@ export declare abstract class Model<T> extends Hooks {
267267
* without
268268
* profiles will be counted
269269
*/
270-
static findAndCount<T extends Model<T>>(options?: IFindOptions): Promise<{rows: T[], count: number}>;
270+
static findAndCount<T extends Model<T>>(options?: IFindOptions<T>): Promise<{rows: T[], count: number}>;
271271

272-
static findAndCountAll<T extends Model<T>>(options?: IFindOptions): Promise<{rows: T[], count: number}>;
272+
static findAndCountAll<T extends Model<T>>(options?: IFindOptions<T>): Promise<{rows: T[], count: number}>;
273273

274274
/**
275275
* Find the maximum value of field

lib/services/scopes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function resolveScope(scopeName: string, model: typeof Model, options: IScopeFin
5454
} else {
5555
options = inferAlias(options, model);
5656
}
57-
model.addScope(scopeName, options as IFindOptions, {override: true});
57+
model.addScope(scopeName, options as IFindOptions<typeof Model>, {override: true});
5858
}
5959

6060
/**

0 commit comments

Comments
 (0)