-
Notifications
You must be signed in to change notification settings - Fork 140
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
PropTypes and Typescript duplication #4466
Comments
I'd love to have a unified Carbon stance on this topic. We should all get together. @elycheea @jeffchew @tay1orjones @kennylam @matthewgallo @lee-chase Maybe a topic for our next Dev call? |
Slack convo excerpts with Taylor.
|
If data suggests there is still a large population not using typescript, and we all firmly agree it's too burdensome to maintain both, we could explore a "soft-deprecation" of proptypes for v12.
With the goal of actually removing proptypes in v13 or something. Personally I'm not totally sold on this (cost/reward seems out of balance), but it's something to talk about. |
@sstrubberg @tay1orjones Sounds like next dev call will have some funteresting topics lined up. 😀 We had a few other we wanted to add to the list. |
I'm wondering how or if our viewpoint on this changes at all when taking into consideration that // Before
import PropTypes from 'prop-types';
function Heading({text}) {
return <h1>{text}</h1>;
}
Heading.propTypes = {
text: PropTypes.string,
};
Heading.defaultProps = {
text: 'Hello, world!',
}; // After
interface Props {
text?: string;
}
function Heading({text = 'Hello, world!'}: Props) {
return <h1>{text}</h1>;
} @tay1orjones I like the idea you posed around possibly generating prop types so that we can maintain support for previous React versions and it would also allow us to remove some of the duplication that we already see in our components. |
The other thing is that having PropTypes bloats the code (i.e. it bloats the output from Webpack). So I understand your desire to be nice to people still using plain Javascript, but it does add a cost to all applications. Of course this applies to @carbon/react as well as @carbon/ibm-products. |
@wkeese Production builds should use something like https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types to strip the proptypes. I'm not sure if the additional size realistically impacts dx during local development. |
Yes, you should do that in your production build of Carbon. But it doesn't matter if I run that plugin in my production build, because that wouldn't affect the code in Carbon. In other words, Babel runs on code in the src/ directory, not in the node_modules/ directory. (I know technically you can configure Babel to run on node_modules/, but it's not practical.) |
Yeah, we can't strip them but we could wrap them in a |
Sounds good although I'm not actually sure what you mean by "flat entrypoint". |
From Feb 27, 2024 retrospective.
Currently, we’re keeping both PropTypes and Typescript, but consider this is also duplication.
(Note that Typescript checks type at compile while PropTypes checks during runtime.)
Duplication does also mean additional work for us longer term if we add or change props.
@lee-chase brought up that some props have custom validation so would need an alternative in order to remove the prop types for these.
The text was updated successfully, but these errors were encountered: