@Types/Sequelize 错误 TS1086:无法在环境上下文中声明访问器

@Types/Sequelize Error TS1086: An accessor cannot be declared in ambient context

我有一个项目在 运行 '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;
         ~~~~

我的版本是:

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

谢谢。

你需要使用 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。

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

我有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

  },