sequelize-typescript decorators(
2019-02-14 本文已影响3人
AsaGuo
1. When I try to declare something like:
// base_table.ts
@Table
export default class base_table extends Model<base_table>{
@Column({
primaryKey: true,
autoIncrement: true
})
id: number;
}
// person.ts
@Table
export default class person extends base_table {
@HasMany(() => book)
books: book[];
}
// book.ts
@Table
export default class book extends base_table {
@ForeignKey(() => person)
@Column
person_id: number;
@BelongsTo(() => person)
person:person;
}
2. I get something like:
TSError: ⨯ Unable to compile TypeScript:
error TS2321: Excessive stack depth comparing types '() => typeof person' and 'ModelClassGetter'.
...
3. solution:
In this case you should have sequelize-typescript only installed on your main project... not additionally in these packages. So that sequelize typescripts doesn‘t get installed more than once in your project.
(xx.ts 和生成的xx.js在同一个文件夹中,让扰乱的sequelize-typescript的编译行为,修改tsconfig.json中的outDir和rootDir为不同的文件夹)