storybook: TS1086: An accessor cannot be declared in an ambient context

Describe the bug Upgraded to 5.3.3 just now and our Angular build is failing with the following:

[ng]
[ng] ERROR in ../../node_modules/@storybook/channels/dist/index.d.ts:25:9 - error TS1086: An accessor cannot be declared in an ambient context.
[ng]
[ng] 25     get hasTransport(): boolean;
[ng]            ~~~~~~~~~~~~

From a quick google, it appears other repos are facing the same issue due to the use of TypeScript 3.7.0 - but Angular is restricted to ❤️.5.0

Similar errors https://github.com/nestjs/nest/issues/3513 https://github.com/googleapis/node-gtoken/issues/244

I believe the breaking change come from TypeScript directly https://github.com/microsoft/TypeScript/issues/33939 - but until a fix is released, the index.d.ts file will need regenerating with npm i typescript@~3.6.0 (swap ^ for ~)

System:

    OS: macOS Mojave 10.14.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 12.14.1 - /usr/local/bin/node
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 79.0.3945.117
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-actions: ^5.3.3 => 5.3.3
    @storybook/addon-knobs: ^5.3.3 => 5.3.3
    @storybook/addon-links: ^5.3.3 => 5.3.3
    @storybook/addon-notes: ^5.3.3 => 5.3.3
    @storybook/addon-storyshots: ^5.3.3 => 5.3.3
    @storybook/addons: ^5.3.3 => 5.3.3
    @storybook/angular: ^5.3.3 => 5.3.3
    @storybook/cli: ^5.3.3 => 5.3.3

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 22
  • Comments: 55 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Try "skipLibCheck": true, inside tsconfig.json eg.

"compilerOptions": {
    "baseUrl": "src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    **"skipLibCheck": true,**
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },

Hope it will help you !!

ng update --next @angular/cli --force npm install typescript@latest

😉

If you’re running older version of Angular, e.g. 8.1.0 you’ll see the following error

The Angular Compiler requires TypeScript >=3.4.0 and <3.5.0 but 3.x.y was found instead.

I had the same issue. I resolve it by update the Typescript package to the latest version

Son of a gun!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.14 containing PR #9847 that references this issue. Upgrade today to try it out!

Closing this issue. Please re-open if you think there’s still more to do.

Updating with ng update --next @angular/cli --force to 9.0.0-rc.12 which uses typescript @ "3.7.5", has helped the issue indeed.

Tente " skipLibCheck": true , dentro do tsconfig.json, por exemplo.

"compilerOptions": {
    "baseUrl": "src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    **"skipLibCheck": true,**
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },

Espero que ajude você !!

Works!!! Thanks

@gaetanmaisse I’m playing around with a branch to utilize downlevel-dts. At first I dismissed it because it’s not a maintained part of TypeScript but after thinking through it a bit, it could be a viable option to let us use TS3.7+ and still be compatible with <=TS3.5 users. Give me a bit to verify the changes and then we can see if it’s worth the maintenance. The build scripts are pretty tidy so this shouldn’t be too difficult.

Getting this same issue with typescript 3.7.5 and storybook/react 5.3.9

I had a stab at doing the upgrade but got lost in the package structure 😅 - The end result (after dist files are generated) should make @storybook/channels/dist/index.d.ts:25 go

From

get hasTransport(): boolean;

To

readonly hasTransport: boolean;

Chiming in - skipLibCheck: true works a charm. This is great for those who can’t risk an ng update mid-QA cycle. Thanks!

@gaetanmaisse PR is up, let me know if you have any questions.

Thanks for the opportunity to contribute!

Upgrading to TypeScript 3.7.x isn’t a great option for library maintainers. This means that the change from 3.6 to 3.7 (technically a breaking change) gets passed down to our consumers and we can’t assume they can readily upgrade TypeScript either.

@ndelangen I think this can be rectified by changing https://github.com/storybookjs/storybook/blob/next/package.json#L218 to typescript@~3.6.0, since typescript@^3.4.0 resolves to 3.7.5 right now. Then we can save the 3.7 upgrade until until Storybook 6.0 since it’s actually a breaking change.

What do you think?

@IsharaMadawa why? Just try to update your typescript version and check if it is working

I had the same issue. I resolve it by update the Typescript package to the latest version

@siropo What version? i’m using angular 8.3.20 and typescript 3.5.3. And i got same error when try to build the project.

Adding “skipLibCheck”: true, in the compilerOptions inside file tsconfig.json worked for me. Thank you so much .

Ok but how to resolve this issue without typescript update?

works for me @lychyi. thanks so much for taking care of this & thinking it through!!! 💯

re: 3.7 in storybook 6.0. i’m not sure about whether 3.7 is necessary, will let one of the typescript guys speak to that @ndelangen @kroeder @gaetanmaisse

@ColCh It will! We are testing that everything is OK on the latest 6.0.0-alpha and then we will release it in a 5.3.x version 😉

@lychyi Great summary. Uninformed gut feel says definitely 3.7 for 6.0. Seize the future!! 😈

Sounds like a plan @lychyi

Want to open a PR against the next branch?

We’ll cherry-pick it into master and release as a patch @shilman

ng update --next @angular/cli --force npm install typescript@latest

😉 It worked,Thank you Snargol.