首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在nestjs中序列化和typescript集成时出错

在nestjs中序列化和typescript集成时出错
EN

Stack Overflow用户
提问于 2021-06-27 11:28:02
回答 2查看 1.9K关注 0票数 8

我正在尝试使用typescript部署带有sequelize的nestJs。

我正在学习本教程:

https://docs.nestjs.com/techniques/database#sequelize-integration

代码语言:javascript
复制
[00:22:10] Starting compilation in watch mode...

node_modules/sequelize-typescript/dist/model/model/model.d.ts:10:31 - error TS2417: Class static side 'typeof import("/var/www/vhosts/curem/temp/node_modules/sequelize-typescript/dist/model/model/model").Model' incorrectly extends base class static side 'typeof import("/var/www/vhosts/curem/temp/node_modules/sequelize/types/lib/model").Model'.
  The types returned by 'init(...)' are incompatible between these types.
    Type 'Model<any, any>' is not assignable to type 'MS'.
      'MS' could be instantiated with an arbitrary type which could be unrelated to 'Model<any, any>'.

10 export declare abstract class Model<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> extends OriginModel<TModelAttributes, TCreationAttributes> {
                                 ~~~~~

node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize.d.ts:12:5 - error TS2416: Property 'model' in type 'Sequelize' is not assignable to the same property in base type 'Sequelize'.
  Type '<TCreationAttributes, TModelAttributes>(model: string | ModelType<TCreationAttributes, TModelAttributes>) => ModelCtor<Model<any, any>>' is not assignable to type '(modelName: string) => ModelCtor<Model<any, any>>'.
    Type 'import("/var/www/vhosts/curem/temp/node_modules/sequelize-typescript/dist/model/model/model").ModelCtor<import("/var/www/vhosts/curem/temp/node_modules/sequelize-typescript/dist/model/model/model").Model<any, any>>' is not assignable to type 'import("/var/www/vhosts/curem/temp/node_modules/sequelize/types/lib/model").ModelCtor<import("/var/www/vhosts/curem/temp/node_modules/sequelize/types/lib/model").Model<any, any>>'.
      Type 'ModelCtor<Model<any, any>>' is not assignable to type 'typeof Model'.
        The types returned by 'init(...)' are incompatible between these types.
          Type 'Model<any, any>' is not assignable to type 'MS'.
            'MS' could be instantiated with an arbitrary type which could be unrelated to 'Model<any, any>'.

12     model<TCreationAttributes, TModelAttributes>(model: string | ModelType<TCreationAttributes, TModelAttributes>): ModelCtor;
       ~~~~~

[00:22:13] Found 2 errors. Watching for file changes.

有人知道如何修复这个错误吗?

EN

回答 2

Stack Overflow用户

发布于 2021-06-28 07:13:02

我刚刚看到了这个问题,它与他们发布的sequalize的上一个版本有关。

请尝试以下版本:

代码语言:javascript
复制
"sequelize": "6.6.2"
票数 14
EN

Stack Overflow用户

发布于 2021-07-24 05:50:12

目前,所有高于6.6.2的版本都无法正常工作。

尝试将package.json文件中的版本更改为"sequelize": "6.6.2"

如果它不能帮助您在自己的模型中检查class model中的扩展。

代码语言:javascript
复制
@Table
export class User extends Model<User, IUser>

更改为:

代码语言:javascript
复制
@Table
export class User extends Model
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68147730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档