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

19,403

Solution 1

you need to use 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.

so presumably sequelize was compiled with typescript 3.7 and emits definition files that previous versions don't understand. So you'll need to upgrade to typescript 3.7 or use an earlier version of sequelize.

Solution 2

I have Angular 8. it is working with typescript version of 3.4.5. so solve this issue do below steps.

step 1) go to the tsconfig.json file

step 2) add skipLibCheck: true in "compilerOptions" object. It works for me.

"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

  },

Solution 3

Setting "skipLibCheck": true worked for me.

Share:
19,403
Josel567
Author by

Josel567

Updated on June 17, 2022

Comments

  • Josel567
    Josel567 almost 2 years

    I have a project that shows this error when I run '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;
             ~~~~
    

    My versions are:

    • "@types/sequelize": "^4.28.6"
    • "sequelize": "^5.8.10"
    • "sequelize-typescript": "1.0.0-beta.4"

    The project works fine with nodemon but fails when I try to compile the typescript. Anyone knows this error?

    Thanks.

  • Shlomi Levi
    Shlomi Levi over 4 years
    What if I can't upgrade to 3.7? have another idea?
  • Aviad Hadad
    Aviad Hadad over 4 years
    @ShlomiLevi Use an earlier version of @types/sequelize
  • Thiago Valentim
    Thiago Valentim over 4 years
    you are right, I had this issue recently and after some searches I discoreved an issue closed in the Github, so to fix the problem I had to upgrade the typescript version to the 3.7.2 version.
  • Fluqz
    Fluqz over 4 years
    ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.7.4 was found instead. Im using Angular 7
  • krishn Patel
    krishn Patel about 4 years
    In which file I need to change this?
  • 29er
    29er about 4 years
    tsconfig.json file
  • Алексей Медведев
    Алексей Медведев about 4 years
    Thanks. "skipLibCheck": true(added to tsconfig that related to NestJs), worked and NestJs with app that inited through nest g ng-app.
  • pontusv
    pontusv over 3 years
    This was a better solution than upgrading our Typescript version. Thanks