【问题标题】:Error in sequelize and typescript integration within nestjsNestjs中的续集和打字稿集成错误
【发布时间】:2021-09-09 20:03:51
【问题描述】:

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

我正在学习本教程:

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

[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.

有人知道如何解决这个错误吗?

【问题讨论】:

  • 您使用的是什么版本的软件包?好像是类型问题

标签: typescript nestjs


【解决方案1】:

我刚看到这个问题,和他们发布的最后一个版本的sequalize有关。

试用版本:

"sequelize": "6.6.2"

【讨论】:

  • 降级到6.6.2 解决了我的问题。 6.6.4 版本似乎有问题。
  • 为什么我降级了,但错误仍然出现,对吧?
  • 它对我不起作用,但我忘记删除升级包 ^6.6.2 => 6.6.2 的插入符号,然后它起作用了,谢谢。
  • @HatemSat 谢谢,删除标记“^”原来是一个区别,现在它正在工作
  • 您知道是否存在未解决的问题吗?几个月过去了,这还没有解决...
【解决方案2】:

目前所有高于6.6.2 的版本都不能正常工作。

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

如果它没有帮助检查您自己模型中类 Model 的扩展。

@Table
export class User extends Model<User, IUser>

改为:

@Table
export class User extends Model

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-18
    • 2021-11-26
    • 1970-01-01
    • 2016-09-02
    • 2019-04-05
    • 2013-08-29
    • 1970-01-01
    • 2017-02-18
    相关资源
    最近更新 更多