美文网首页
sequelize-typescript decorators(

sequelize-typescript decorators(

作者: AsaGuo | 来源:发表于2019-02-14 14:44 被阅读3次

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为不同的文件夹)

相关文章

网友评论

      本文标题:sequelize-typescript decorators(

      本文链接:https://www.haomeiwen.com/subject/buseeqtx.html