storybook: Addon-docs: Source doc block Typescript support
Describe the bug
As documented in the Technical Preview guide, using typescript without passing sourceLoaderOptions: null
into the docs preset causes the following error:
Variable '__MODULE_DEPENDENCIES__' implicitly has an 'any[]' type
This is unfortunately not fixed by updating the storybook tsconfig.json
to use "noImplicitAny": false
.
To Reproduce Steps to reproduce the behavior:
- Write a story for
addon-docs
using Typescript and the docs preset - Run storybook
Expected behavior Docs page loads, as usual, and a code snippet is available for the story.
Screenshots If applicable, add screenshots to help explain your problem.
Code snippets
presets.js
:
{
name: '@storybook/addon-docs/react/preset',
options: {
sourceLoaderOptions: null,
},
}
System: Environment Info:
System: OS: macOS 10.14.5 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Binaries: Node: 10.16.0 - /usr/local/opt/node@10/bin/node Yarn: 1.17.3 - ~/workspace/component-library/node_modules/.bin/yarn npm: 6.9.0 - /usr/local/opt/node@10/bin/npm Browsers: Chrome: 76.0.3809.100 Safari: 12.1.1 npmPackages: @storybook/addon-a11y: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addon-actions: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addon-docs: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addon-knobs: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addon-links: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addon-viewport: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/addons: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/preset-scss: 1.0.2 => 1.0.2 @storybook/preset-typescript: 1.1.0 => 1.1.0 @storybook/react: ^5.2.0-beta.36 => 5.2.0-beta.38 @storybook/theming: ^5.2.0-beta.36 => 5.2.0-beta.38
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 15
- Comments: 69 (28 by maintainers)
A temporary solution if you use awesome-typescript-loader:
Not ideal, but it works.
Any updates on this? We’re trying to use storybook addons with TS and can’t get past this even with the workarounds. Continue to receive “Variable ‘MODULE_DEPENDENCIES’ implicitly has an ‘any[]’ type.”
Currently have tried updating storybook to 5.3.0-beta.16 and tried the other workarounds mentioned here. Thanks
I just updated from 5.1 to 5.2.5 today and started getting this error, without installing addon-docs yet. This solution worked for me, although I have to say it’s not really clear to my why.
I have update both
@storybook/react
and@storybook/addon-docs
to 5.3.0-rc.4 but keep getting the error messageTS7005: Variable '__MODULE_DEPENDENCIES__' implicitly has an 'any[]' type.
I’m not using the preset and also I’m new to webpack so probably I made some mistakes. Here is my webpack.config.js:
@sami616 @sergiop I install react-docgen-typescript-loader version 3.2.1 I found some code in node_modules/react-docgen-typescript-loader/dist/generateDocgenCodeBlock
&& typeof defaultValue.value === 'string'
this condition limit the typeof defaultProps.
And In the newest version 3.3.0 react-docgen-typescript-loader, It supoort string、number、boolean
https://github.com/strothj/react-docgen-typescript-loader/blob/master/src/generateDocgenCodeBlock.ts
@zerofront @enagy27 yesterday I discovered that my issue (that was apparently the same of @zerofront) was caused exactly by the return type on function.
This fixed for me:
Source: https://github.com/strothj/react-docgen-typescript-loader/issues/42#issuecomment-535090697 And partially this note could be related: https://github.com/strothj/react-docgen-typescript-loader#react-component-class-import
I hope this can help.
@zerofront I can confirm updating
react-docgen-typescript-loader
to 3.3.0 will solve the issue. Thanks.Now that docs has been released I may be able to take some time to update cra-ts-kitchen-sink to make sure we’re all on the same page for configuration 🙂 it may be a week or so though… for now I’ll provide my config:
.storybook/addons.js
.storybook/config.js
.storybook/presets.js
.storybook/theme.js
I can’t share this because it’s internal to my company, but it’s referenced in
config.js
..storybook/tsconfig.json
This file only serves to remove configurations in the root
tsconfig.json
that wouldn’t make sense here in storybook.The TS instructions point you to
react-docgen-typescript-loader
which says to installaddon-info
but earlier in the documentation doesn’t it saysaddon-docs
is a replacement foraddon-info
? Would be super helpful to see a working setup of this with TS or some clear instructions in one place specifically for setting upaddon-docs
with TS.Happy to contribute and help out but need to understand how these pieces fit together first! 👍
@enagy27 You rock for figuring this out. I’m hoping that @libetl will come back online at some point in 5.3, and we can just upgrade
source-loader
so that these workarounds are not needed. Fingers crossed! 🤞Hello @shilman Thanks for the amazing support for docs combined with storybook. I updated to
5.3.0-rc.5
and I still get the errorTS7005: Variable '__MODULE_DEPENDENCIES__' implicitly has an 'any[]' type.
It works only if I add
ignoreDiagnostics: [7005]
to thets-loader
configuration as shown below.file
main.js
:Follow up, I got it working using the
transpileOnly
option mentioned by @enagy27. I am using presets instead of full webpack configs, this is currently mypresets.js
. No changing in thetsconfig.json
:@jalooc please check out 5.3 beta. Tons of improvements to the props table.
@sami616, as already told, I want to open a bug report on this, but before to do it I need to investigate a little on the codebase, to understand if the source of the issue is
storybook
orreact-docgen-typescript-loader
. In this way I’ll open the issue on the right project.Ignore my comment, yes im having the same issue.
Hi, @enagy27. thanks for this. I have got this working with the config you shared。but there is still some promble. It cannot generate component description and props description when I write component with tsx. but it work with jsx。
Hi. Can someone provide an example repo where storybook with react typescript and docs are working?
I’ve found a workaround!
sourceLoaderOptions: null
, I usedtranspileOnly: true
in mytsLoaderOptions
parameters
variableas 'optionA' | 'optionB'
failed here and had to be converted to left-hand type declarations.This fails:
This works:
In hindsight this seems like an understandable
source-loader
issue with type inference 🤔 anyway, hope this helps!No longer seeing issues with
rc.4
, but no source 😞 Though it looks like this is also marked in #6641, so now that the errors are no longer present, this issue may be a duplicate