File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
- import { ModelOptions } from "sequelize" ;
1
+ import { Model , ModelOptions } from "sequelize" ;
2
2
3
- export interface TableOptions extends ModelOptions {
3
+ export interface TableOptions < M extends Model = Model > extends ModelOptions < M > {
4
4
modelName ?: string ;
5
5
6
6
/**
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import {TableOptions} from "./table-options";
2
2
import { Model } from "../model/model" ;
3
3
import { setModelName , addOptions } from "../shared/model-service" ;
4
4
5
- export function Table ( options : TableOptions ) : Function ;
5
+ export function Table < M extends Model = Model > ( options : TableOptions < M > ) : Function ;
6
6
export function Table ( target : Function ) : void ;
7
7
export function Table ( arg : any ) : void | Function {
8
8
Original file line number Diff line number Diff line change @@ -10,3 +10,16 @@ export class User extends Model {
10
10
@Column ( DataType . ARRAY ( DataType . STRING ) )
11
11
myCol : string [ ] ;
12
12
}
13
+
14
+ @Table < Post > ( {
15
+ hooks : {
16
+ beforeUpdate : ( instance ) => {
17
+ // without generic random will result in error
18
+ instance . random = 4 ;
19
+ } ,
20
+ } ,
21
+ } )
22
+ export class Post extends Model {
23
+ @Column ( DataType . INTEGER )
24
+ random : number ;
25
+ }
You can’t perform that action at this time.
0 commit comments