【问题标题】:@Types/Sequelize Error TS1086: An accessor cannot be declared in ambient context@Types/Sequelize 错误 TS1086:无法在环境上下文中声明访问器
【发布时间】:2020-03-07 04:56:09
【问题描述】:

我有一个项目在运行“tsc”时显示此错误:

../modules/node_modules/sequelize/types/lib/transaction.d.ts:33:14 - error TS1086: An accessor cannot be declared in an ambient context.

33   static get LOCK(): LOCK;
                ~~~~

../modules/node_modules/sequelize/types/lib/transaction.d.ts:40:7 - error TS1086: An accessor cannot be declared in an ambient context.

40   get LOCK(): LOCK;
         ~~~~

我的版本是:

  • “@types/sequelize”:“^4.28.6”
  • “续集”:“^5.8.10”
  • “sequelize-typescript”:“1.0.0-beta.4”

该项目在 nodemon 上运行良好,但在我尝试编译打字稿时失败。有人知道这个错误吗?

谢谢。

【问题讨论】:

    标签: node.js typescript types sequelize.js tsc


    【解决方案1】:

    您需要使用 typescript 3.7。

    from typescript 3.7 release notes:

    To detect the issue around accessors, TypeScript 3.7 will now emit get/set accessors in .d.ts files so that in TypeScript can check for overridden accessors.
    
    

    所以大概sequelize 是用 typescript 3.7 编译的,并发出以前版本不理解的定义文件。所以你需要升级到 typescript 3.7 或者使用更早版本的 sequelize。

    【讨论】:

    • 无法升级到 3.7 怎么办?有其他想法吗?
    • @ShlomiLevi 使用早期版本的@types/sequelize
    • 你说得对,我最近遇到了这个问题,经过一些搜索后,我发现在 Github 中关闭了一个问题,所以为了解决这个问题,我不得不将 typescript 版本升级到 3.7.2 版本。
    • Angular 编译器中的错误需要 TypeScript >=3.1.1 和
    【解决方案2】:

    设置 "skipLibCheck": true 对我有用。

    【讨论】:

    • 我需要在哪个文件中更改?
    • tsconfig.json 文件
    【解决方案3】:

    我有 Angular 8。它正在使用 3.4.5 的打字稿版本。因此,请按照以下步骤解决此问题。

    第 1 步)转到 tsconfig.json 文件

    步骤 2) 在“compilerOptions”对象中添加 skipLibCheck: true。这个对我有用。

    "compilerOptions": {
        "module": "commonjs",
        "moduleResolution": "node",
        "strict": true,
        "target": "es5",
        "declaration": true,
        "declarationDir": "dist-debug/",
        "skipLibCheck": true, /// Needs to be true to fix wrong alias types being used
    
      },
    

    【讨论】:

    • 谢谢。 “skipLibCheck”:true(添加到与 NestJs 相关的 tsconfig),与通过 Nest g ng-app 启动的应用程序一起工作和 NestJs。
    • 这是一个比升级我们的 Typescript 版本更好的解决方案。谢谢
    猜你喜欢
    • 2021-07-09
    • 2020-05-22
    • 2020-05-24
    • 2020-07-21
    • 2020-07-09
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多