-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-docs: Source doc block Typescript support #7829
Comments
Thanks @enagy27! There are at least a few options here:
I'm thinking third option is the most straightforward to start, first is probably best long-term |
Great Caesar's ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-beta.39 containing PR #7831 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
@enagy27 don't have a repro, so it would be great if you could give this a try and let me know if it works |
@shilman absolutely! Giving it a shot now. Thank you! |
@shilman still seeing these errors on
Results of
|
Given that this is on the source loader, does that need to be installed separately and then it's taken up by the preset, or is a new release of the preset required? |
@shilman I'm only able to start the server when |
Whoopee!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-beta.40 containing PR #7845 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
@enagy27 Merged & released your changes. Give it a try? |
@shilman no such luck 😞 I'm experimenting locally and can't seem to get the hang of it. I even cheated and marked them all as |
I am also experiencing this issue but unfortunately don't have much additional context. Another solution here is to override all of the "strict" typechecking rules in the |
@libetl I know you're really busy but it would be awesome if you could take a look at this one. |
@JonKrone when you do this do you see the source code in the docs tab? I've made these modifications and I'm still not seeing source 😞 |
A temporary solution if you use awesome-typescript-loader: /* tsconfig.json */
{
"compilerOptions": { },
"awesomeTypescriptLoaderOptions": {
"ignoreDiagnostics": [7005]
}
} Not ideal, but it works. |
@shilman Is this what you're looking for? FYI this wouldn't build without ignoring TS7005 (no implicit any). // @ts-ignore
var withSourceLoader = require('@storybook/source-loader/preview').withSource;
// @ts-ignore
var __SOURCE_PREFIX__ = "/home/user/projects/real/ts/my-blog-react/src/graphql";
// @ts-ignore
var __STORY__ = "import React from \"react\";\n\nimport { ApolloProvider } from \"@apollo/react-hooks\";\nimport { storiesOf } from \"@storybook/react\";\n\nimport { Posts } from \"../views/Posts/index\"; // ! Fix coupling\nimport { PostContent } from \"../views/PostContent\"; // ! Fix coupling\nimport { withPostContentQuery } from \"./components/withPostContentQuery\";\nimport { withPostsQuery } from \"./components/withPostsQuery\";\nimport * as fakeQl from \"./fakeql/fakeql-endpoints\";\nimport apolloClientFactory from \"./apollo\";\n\n// FIXME: #coupling - find a way to not depend on Post and Container, probably fakes - but not good enough.\n\nconst apolloClient = apolloClientFactory(fakeQl.normalApiEndpoint);\nconst PostContentQuery = withPostContentQuery(PostContent);\nconst PostsQuery = withPostsQuery(Posts);\n\n// ~~~ Posts ~~~\nstoriesOf(\"GraphQL\", module).add(\"PostsQuery\", () => (\n <ApolloProvider client={apolloClient}>\n <PostsQuery routeHandler={() => null} />\n </ApolloProvider>\n));\n\n// ~~~ PostContent ~~~\nstoriesOf(\"GraphQL\", module).add(\"PostContentQuery\", () => (\n <ApolloProvider client={apolloClient}>\n <PostContentQuery postId=\"1\" />\n </ApolloProvider>\n));\n";
// @ts-ignore
var __ADDS_MAP__ = {"graphql--postsquery":{"startLoc":{"col":33,"line":20},"endLoc":{"col":1,"line":24},"startBody":{"col":47,"line":20},"endBody":{"col":1,"line":24}},"graphql--postcontentquery":{"startLoc":{"col":33,"line":27},"endLoc":{"col":1,"line":31},"startBody":{"col":53,"line":27},"endBody":{"col":1,"line":31}}};
// @ts-ignore
var __MAIN_FILE_LOCATION__ = "/root.stories.tsx";
// @ts-ignore
var __MODULE_DEPENDENCIES__ = [];
// @ts-ignore
var __LOCAL_DEPENDENCIES__ = {};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = {};
import React from "react";
import { ApolloProvider } from "@apollo/react-hooks";
import { storiesOf } from "@storybook/react";
import { Posts } from "../views/Posts/index"; // ! Fix coupling
import { PostContent } from "../views/PostContent"; // ! Fix coupling
import { withPostContentQuery } from "./components/withPostContentQuery";
import { withPostsQuery } from "./components/withPostsQuery";
import * as fakeQl from "./fakeql/fakeql-endpoints";
import apolloClientFactory from "./apollo";
// FIXME: #coupling - find a way to not depend on Post and Container, probably fakes - but not good enough.
const apolloClient = apolloClientFactory(fakeQl.normalApiEndpoint);
const PostContentQuery = withPostContentQuery(PostContent);
const PostsQuery = withPostsQuery(Posts);
// ~~~ Posts ~~~
storiesOf("GraphQL", module).addParameters({ storySource: { source: __STORY__, locationsMap: __ADDS_MAP__ } }).addDecorator(withSourceLoader(__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__)).add("PostsQuery", () => (
<ApolloProvider client={apolloClient}>
<PostsQuery routeHandler={() => null} />
</ApolloProvider>
));
// ~~~ PostContent ~~~
storiesOf("GraphQL", module).addParameters({ storySource: { source: __STORY__, locationsMap: __ADDS_MAP__ } }).addDecorator(withSourceLoader(__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__)).add("PostContentQuery", () => (
<ApolloProvider client={apolloClient}>
<PostContentQuery postId="1" />
</ApolloProvider>
));
|
@0b10 I'll give it a shot, thank you! We are currently ignoring all of those lines, but I hadn't thought to change my |
"No code avaliable" on my TSX stories, MDX works fine, result looks similar/exactly like @0b10's story // @ts-ignore
var withSourceLoader = require('@storybook/source-loader/preview').withSource;
// @ts-ignore
var __SOURCE_PREFIX__ = "C:\\Workspace\\application-ui\\src\\components\\atoms\\container";
// @ts-ignore
var __STORY__ = "import { storiesOf } from \"@storybook/react\";\nimport React, { ReactElement } from \"react\";\n\nimport { Container } from \"components\";\n\nconst stories = storiesOf(\"Atoms/Container\", module).addParameters({ component: Container });\n\nstories.add(\"Default\", (): ReactElement => <Container>Hello</Container>);\n";
// @ts-ignore
var __ADDS_MAP__ = {};
// @ts-ignore
var __MAIN_FILE_LOCATION__ = "/Container.stories.tsx";
// @ts-ignore
var __MODULE_DEPENDENCIES__ = [];
// @ts-ignore
var __LOCAL_DEPENDENCIES__ = {};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = {};
import { storiesOf } from "@storybook/react";
import React, { ReactElement } from "react";
import { Container } from "components";
const stories = storiesOf("Atoms/Container", module).addParameters({ storySource: { source: __STORY__, locationsMap: __ADDS_MAP__ } }).addDecorator(withSourceLoader(__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__)).addParameters({ component: Container });
stories.add("Default", (): ReactElement => <Container>Hello</Container>); |
Updated config.js as it was just docs: {
container: DocsContainer,
page: DocsPage,
}, Presets: module.exports = [
{
name: "@storybook/addon-docs/react/preset",
options: {
configureJSX: true,
},
},
]; Webpack config, possibly not needed?
tsconfig.json includes |
No longer seeing issues with |
I've found a workaround!
This fails:
This works:
In hindsight this seems like an understandable |
@jalooc please check out 5.3 beta. Tons of improvements to the props table. |
@shilman I believe I tried this last on beta.6 and it wasn’t functioning without the workaround. I’ll try again with the latest 😄 |
I still get this problem with storybook [email protected] and react-docgen-typescript-loader 3.6.0. The only way to fix it for me was to set The error I am getting is this one: Even if I add a type to my stories it doesn't fix the problem fully. |
Follow up, I got it working using the // presets.js
const path = require("path");
module.exports = [
{
name: "@storybook/preset-typescript",
options: {
tsLoaderOptions: {
configFile: path.resolve(__dirname, "../tsconfig.json"),
transpileOnly: true,
},
tsDocgenLoaderOptions: {
tsconfigPath: path.resolve(__dirname, "../tsconfig.json"),
},
include: [path.resolve(__dirname, "../src")],
},
},
{
name: "@storybook/addon-docs/react/preset",
options: {
configureJSX: true,
//sourceLoaderOptions: null,
},
},
]; |
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 Currently have tried updating storybook to 5.3.0-beta.16 and tried the other workarounds mentioned here. Thanks |
I can't get storybook addon-docs to show the props table with typescript. It just says "No component found". addons.js
presets.js
webpack.config.js
Storybook 5.2.8 Also, if I use Component Story Format storybook doesn't find the component at all (canvas and docs and menu are blank), but if I use storiesOf it displays them. |
As a workaround you can point doc generation towards tsconfig.json with strict rules turned off. I guess I solved it like this for now. Can recheck next week if anyone interested. |
For anyone else still struggling, I've finally managed to get it to work after some painful debugging of react-docgen-typescript-loader. React-docgen-typescript-loader assigns the
I couldnt get CSF format to work (always blank), but when using the
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Typescript should be working in the source block in 5.3. Closing. |
I have update both I'm not using the preset and also I'm new to webpack so probably I made some mistakes.
|
Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-rc.5 containing PR #9272 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
@JacopoBonta can you try the most recent release |
Hello @shilman Thanks for the amazing support for docs combined with storybook. It works only if I add file
|
I'm sorry but upgrading to |
@JacopoBonta can you verify @esakal's workaround? |
@JacopoBonta I see that you are using
taken from here |
Yes, it works. I was already using this workaround before but I was looking for a way without it. Anyway, thanks for the helps I have appreciated a lot and happy new year 🎉 |
Thank you @esakal you solution is the best (for me) so far. I used to set My current, pretty minimal configuration ( const path = require("path");
module.exports = [
{
name: "@storybook/preset-typescript",
options: {
tsLoaderOptions: {
configFile: path.resolve(__dirname, "../tsconfig.json"),
ignoreDiagnostics: [7005],
},
},
},
{
name: "@storybook/addon-docs/preset",
options: {
configureJSX: true,
},
},
]; Thank you! |
Describe the bug
As documented in the Technical Preview guide, using typescript without passing
sourceLoaderOptions: null
into the docs preset causes the following error:This is unfortunately not fixed by updating the storybook
tsconfig.json
to use"noImplicitAny": false
.To Reproduce
Steps to reproduce the behavior:
addon-docs
using Typescript and the docs presetExpected 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
:System:
Environment Info:
System:
OS: macOS 10.14.5
CPU: (16) x64 Intel(R) Core(TM) 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
The text was updated successfully, but these errors were encountered: