web-dev-qa-db-ja.com

@ Types / SequelizeエラーTS1086:アンビエントコンテキストではアクセサーを宣言できません

'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"
  • "sequelize": "^ 5.8.10"
  • 「sequelize-TypeScript」:「1.0.0-beta.4」

プロジェクトはnodemonで正常に動作しますが、TypeScriptをコンパイルしようとすると失敗します。誰かがこのエラーを知っていますか?

ありがとう。

9
Josel567

typeScript 3.7を使用する必要があります。

TypeScript 3.7リリースノートから:

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を使用する必要があります。

13
Aviad Hadad

Angular 8があります。 TypeScriptバージョン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

  },
13
krishn Patel

設定"skipLibCheck": trueは私のために働きました。

4
kimamula