1-
21import { Promise } from './promise' ;
32import { Col , Fn , Literal , Where } from './utils' ;
43import { SyncOptions } from './sequelize' ;
@@ -272,7 +271,7 @@ export interface IncludeThroughOptions {
272271/**
273272 * Options for eager-loading associated models, also allowing for all associations to be loaded at once
274273 */
275- export type Includeable = Model | Association | IncludeOptions | { all : true } ;
274+ export type Includeable = typeof Model | Association | IncludeOptions | { all : true } ;
276275
277276/**
278277 * Complex include options
@@ -449,6 +448,10 @@ export interface FindOptions {
449448 */
450449 subQuery ?: boolean ;
451450
451+ /**
452+ * Throw if nothing was found.
453+ */
454+ rejectOnEmpty ?: boolean ;
452455}
453456
454457/**
@@ -1839,15 +1842,19 @@ export abstract class Model {
18391842 * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will
18401843 * always be called with a single instance.
18411844 */
1842- static findById < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier ?: number | string , options ?: FindOptions ) : Promise < M | null > ;
1843- static findByPrimary < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier ?: number | string , options ?: FindOptions ) : Promise < M | null > ;
1845+ static findById < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier ?: number | string , options ?: FindOptions & { rejectOnEmpty ?: false } ) : Promise < M | null > ;
1846+ static findById < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier : number | string , options : FindOptions & { rejectOnEmpty : true } ) : Promise < M > ;
1847+ static findByPrimary < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier ?: number | string , options ?: FindOptions & { rejectOnEmpty ?: false } ) : Promise < M | null > ;
1848+ static findByPrimary < M extends Model > ( this : { new ( ) : M } & typeof Model , identifier : number | string , options : FindOptions & { rejectOnEmpty : true } ) : Promise < M > ;
18441849
18451850 /**
18461851 * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single
18471852 * instance.
18481853 */
1849- static findOne < M extends Model > ( this : { new ( ) : M } & typeof Model , options ?: FindOptions ) : Promise < M | null > ;
1850- static find < M extends Model > ( this : { new ( ) : M } & typeof Model , options ?: FindOptions ) : Promise < M | null > ;
1854+ static findOne < M extends Model > ( this : { new ( ) : M } & typeof Model , options ?: FindOptions & { rejectOnEmpty ?: false } ) : Promise < M | null > ;
1855+ static findOne < M extends Model > ( this : { new ( ) : M } & typeof Model , options : FindOptions & { rejectOnEmpty : true } ) : Promise < M > ;
1856+ static find < M extends Model > ( this : { new ( ) : M } & typeof Model , options ?: FindOptions & { rejectOnEmpty ?: false } ) : Promise < M | null > ;
1857+ static find < M extends Model > ( this : { new ( ) : M } & typeof Model , options : FindOptions & { rejectOnEmpty : true } ) : Promise < M > ;
18511858
18521859 /**
18531860 * Run an aggregation method on the specified field
@@ -1858,7 +1865,7 @@ export abstract class Model {
18581865 * @return Returns the aggregate result cast to `options.dataType`, unless `options.plain` is false, in
18591866 * which case the complete data result is returned.
18601867 */
1861- aggregate ( field : keyof this, aggregateFunction : string , options ?: AggregateOptions ) : Promise < any > ;
1868+ aggregate < K extends keyof this> ( field : K , aggregateFunction : string , options ?: AggregateOptions ) : Promise < any > ;
18621869 static aggregate < M extends Model > ( this : { new ( ) : M } & typeof Model , field : keyof M , aggregateFunction : string , options ?: AggregateOptions ) : Promise < any > ;
18631870
18641871 /**
@@ -2517,8 +2524,8 @@ export abstract class Model {
25172524 *
25182525 * If changed is called without an argument and no keys have changed, it will return `false`.
25192526 */
2520- changed ( key : keyof this) : boolean ;
2521- changed ( key : keyof this, dirty : boolean ) : void ;
2527+ changed < K extends keyof this> ( key : K ) : boolean ;
2528+ changed < K extends keyof this> ( key : K , dirty : boolean ) : void ;
25222529 changed ( ) : false | string [ ] ;
25232530
25242531 /**
@@ -2592,7 +2599,7 @@ export abstract class Model {
25922599 * If an array is provided, the same is true for each column.
25932600 * If and object is provided, each column is incremented by the value given.
25942601 */
2595- increment ( fields : keyof this | ( keyof this ) [ ] | Partial < this> , options ?: IncrementDecrementOptions ) : Promise < this> ;
2602+ increment < K extends keyof this> ( fields : K | K [ ] | Partial < this> , options ?: IncrementDecrementOptions ) : Promise < this> ;
25962603
25972604 /**
25982605 * Decrement the value of one or more columns. This is done in the database, which means it does not use
@@ -2614,7 +2621,7 @@ export abstract class Model {
26142621 * If an array is provided, the same is true for each column.
26152622 * If and object is provided, each column is decremented by the value given
26162623 */
2617- decrement ( fields : keyof this | ( keyof this ) [ ] | Partial < this> , options ?: IncrementDecrementOptions ) : Promise < this> ;
2624+ decrement < K extends keyof this> ( fields : K | K [ ] | Partial < this> , options ?: IncrementDecrementOptions ) : Promise < this> ;
26182625
26192626 /**
26202627 * Check whether all values of this and `other` Instance are the same
0 commit comments