-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Convert packages/react storybook to typescript. Convert checkbox story to tsx #12000
Conversation
Add typescript dependency to carbon/react. Convert storybook main.js and Checkbox story to ts.
fix: change tsconfig module to commonjs
DCO Assistant Lite bot All contributors have signed the DCO. |
✅ Deploy Preview for carbon-components-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
I have read the DCO document and I hereby sign the DCO. |
@mbarrer Are you using Yarn v1 by chance? The project is configured to need Since you added new dependencies there should also be some additions to |
Ah yes I have yarn 1.22.18 installed, I can update this on my end and run a fresh yarn install. I didnt see any |
@mbarrer Hey so out of curiosity I pulled down this PR, reset Anyway, should be fixed now 👍 |
packages/react/.storybook/main.ts
Outdated
const babelLoader = config.module.rules.find((rule) => { | ||
return rule.use.some(({ loader }) => { | ||
// TODO: Fix typings for this function | ||
webpack(config: any) { |
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.
If statically typing this is desired, there are two options:
- Only use
Configuration
type from Webpack
import type { Configuration } from 'webpack';
...
webpack(config: Configuration) {
- Type the entire config using
StorybookConfig
import type { StorybookConfig } from '@storybook/core-common';
const config: StorybookConfig = { /** */ }
module.exports = config;
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.
Yep nice call, there was a few other changes needed in the body of the config to account for the union types used in the webpackFinal
prop. The use of the typings also caught the fact that the webpack
property should have actually been renamed to webpackFinal
according to the storybook 6.5 docs
Looks like the build task also needs to be adjusted to output a main.js file for use in netlify, will be taking a look at this |
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.
This looks good to me.
I was concerned about what would happen if we released this without all the other types, or at least empty export declare let XX = unknown
declarations for everything so I looked in the compiled lib and es folders and it doesn't look like it's actually shipping the types there yet and carbon doesn't ship the src folder. When we want to "go live" with the feature, I believe they'll need to be copied to the appropriate place along with an index.d.ts file.
Given all that, this looks like a great way to dark release our work.
Just letting you guys know that I haven't forgot about this PR, have just been busy this week with story work. I'll aim to have the build issue resolved by the end of the week |
packages/react/.storybook/main.ts
Outdated
@@ -4,19 +4,17 @@ | |||
* This source code is licensed under the Apache-2.0 license found in the | |||
* LICENSE file in the root directory of this source tree. | |||
*/ | |||
import fs from 'fs'; |
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.
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.
oh cool I didnt know you could reference these like this. good to know!
Seems like the issue I was hitting was something that @erifsx brought up in a thread on the workgroup slack. We found that we didnt need ts-node to get things running initially but for some reason this is now required in order to run the main.ts. Adding this to the dev dependancies seems to resolve the issues with netlify |
{ | ||
files: ['*.ts', '*.tsx'], | ||
plugins: ['@typescript-eslint'], | ||
extends: ['plugin:@typescript-eslint/recommended'], | ||
}, |
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.
Assuming carbon is using the no-unused-vars
JS rule, you'll want to turn that off in favor of the typescript-eslint one. Here's an example
@@ -0,0 +1,7 @@ | |||
import { FunctionComponent, HTMLAttributes } from 'react'; |
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.
Missing copyright statement
@@ -0,0 +1,52 @@ | |||
import * as React from 'react'; |
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.
Missing copyright statement
@@ -0,0 +1,5 @@ | |||
import Checkbox from './Checkbox'; |
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.
Missing copyright statement
@@ -1,3 +1,4 @@ | |||
/* eslint-disable jest/no-standalone-expect */ |
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.
Which part of this file is violating this rule? Should it instead be updated to conform to it?
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.
Hmm not sure why this was added, removing does not seem to cause any warnings to show
packages/react/src/custom.d.ts
Outdated
@@ -0,0 +1,5 @@ | |||
// Ambient module to allow the importing of .mdx files in storybook .tsx files | |||
declare module '*.mdx' { | |||
const content: any; |
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.
We should definitely aim for zero warnings. This should either be unknown
or if working around the lack of explicit any
is too onerous to devs (since this is a gradual conversion), perhaps we consider disabling the no-explicit-any
rule to start.
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.
Good point, i should have changed this to unknown
@jdharvey-ibm updated PR based off your recent comments |
Closing in favor of #12222 |
Closes #11587
Changes have been made to allow the use of typescript within
packages/react
so that storybook stories can start to be written in typescript. As part of this change, the main.js for storybook has now been converted to main.ts and has some initial typings. Typing files have been added for Checkbox that we're sourced from the DefinitelyTyped repo and adjusted for carbon v11Changelog
New
"typescript": "^4.7.4"
"@typescript-eslint/eslint-plugin": "^5.30.5"
and"@typescript-eslint/parser": "^5.34.0"
for linting"ts-node": "^10.9.1"
for supporting imports in storybook main.tstypings/shared.d.ts
common types file pulled from DefinitielyTypedcomponents/Checkbox/Checkbox.d.ts
new typing file for Checkbox (adjusted DT typings)custom.d.ts
ambient module to allow imports of .mdx files in .tsxtsconfig.json
Changed
mini-css-extract-plugin
to support native ts typings.storybook/main.js
to typescript and allow stories to be written in typescriptcomponents/Checkbox/Checkbox.stories.js
to tsx using the new typingseslint-config-carbon/plugins/react.js
Testing / Reviewing
In order to test: