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
Add TypeScript support for react-scripts #4824
Conversation
Codecov Report
@@ Coverage Diff @@
## next #4824 +/- ##
=========================================
+ Coverage 35.5% 35.55% +0.04%
=========================================
Files 560 560
Lines 6818 6827 +9
Branches 913 915 +2
=========================================
+ Hits 2421 2427 +6
- Misses 3919 3920 +1
- Partials 478 480 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Thanks for taking it.
Do you want to add CLI tests for this in a separate PR?
@igor-dv Definitely, I can take a look at that over the weekend. I've squashed and pushed those changes, thanks for the review. |
Thanks for this work! Do I understand it correctly that now, using Storybook 4.1, we can:
And follow-up in case the latter is false: is there anything that needs to be done to enable writing stories in TypeScript, other than renaming them from |
If you are using CRA2 you can use TS for all also in storybook |
Yes, all of my team's stories are |
@mrmckeb Hmm, and you've removed your custom webpack.config.js and don't have a TypeScript loader in your own dependencies? I'm asking because I'm running into
So it appears that for some reason, without my own Webpack config, Storybook's config does not look for TypeScript files. |
Hi @Vinnl, can you let me know what version of |
Of course @mrmckeb :) |
Hmm, where are you stories located? In component directories? Perhaps you could push up a quick test repo that I could play with? Something very rough. |
@mrmckeb The stories are in Update: With the following module.exports = (baseConfig, env, config) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
},
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
} Second update: vstelmakh on Slack confirmed that it's not working without configuration for them either. Final update: Moving the stories to be located within |
Sorry @Vinnl, I see what's wrong now. Our config (at create-react-app) supports files inside of You can either add your stories folder to src, or use another approach. Personally, I keep stories alongside each component ( The custom webpack config you have provided is not necessary, if you really want to keep a stories folder outside of src, you can simply add that to the I hope that helps! |
Thanks for working on this at all @mrmckeb - you don't owe me anything, so that's very generous :) But you were entirely correct! Moving the stories into the |
@mrmckeb we probably need to add |
I actually feel that this is not a good default. I much prefer stories to be alongside components - perhaps that should be the default? This results in less jumping between folders, and a smaller chance that people will forget to update stories after changing components (which I've seen a lot). Regardless, this is a very easy fix if we want to add it ;) |
Yeah, that is how most of the people work with stories, IMO. Though I am not sure it's easy to do this with the cli at least now... |
Issue: #4587
What I did
Added support for TypeScript when using
react-scripts@>=2.1.0
.How to test
Create a new Create React App project and pass in the
--typescript
flag.Install storybook (this build) and run
storybook
. You should not see any errors.