Skip to content
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

Open
elycheea opened this issue Mar 5, 2024 · 10 comments
Open

PropTypes and Typescript duplication #4466

elycheea opened this issue Mar 5, 2024 · 10 comments
Labels
adopter: automation Issues connected to work that accelerates IBM's automation offerings. adopter: data & ai Issues connected to work that accelerates IBM's Data & AI offerings. adopter: security Issues connected to work that accelerates IBM's Security offerings. adopter: sustainability Issues connected to work that accelerates IBM's sustainability offerings. area: typescript role: dev type: enhancement 💡 New feature or request type: infrastructure 🤖 Issues related to devops, builds, packaging type: process 🎞️ Process and other project mgmt tasks or discussions type: question ❓ Further information is requested

Comments

@elycheea
Copy link
Contributor

elycheea commented Mar 5, 2024

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.

Image

@lee-chase brought up that some props have custom validation so would need an alternative in order to remove the prop types for these.

@elycheea elycheea converted this from a draft issue Mar 5, 2024
@elycheea elycheea added type: question ❓ Further information is requested type: process 🎞️ Process and other project mgmt tasks or discussions type: infrastructure 🤖 Issues related to devops, builds, packaging area: typescript labels Mar 5, 2024
@sstrubberg sstrubberg moved this from Needs triage 🧐 to Icebox 🧊 in Carbon for IBM Products Apr 8, 2024
@sstrubberg
Copy link
Member

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?

@sstrubberg
Copy link
Member

sstrubberg commented Apr 8, 2024

Slack convo excerpts with Taylor.

  • We don't think it's a good idea to remove proptypes right now. There are apps out there not using typescript and therefore relying on PropTypes. This is a play to maximize our compatibility.
  • If we were to remove them, we would need to gather data that suggests doing so is the right play.
  • Removing would qualify as a breaking change.

@tay1orjones
Copy link
Member

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.

  • Begin generating proptypes from typescript interface(s) instead of manually authoring them
  • Declare typescript interfaces the "source of truth" instead of proptypes
    • Update documentation (website, storybook, repo md(x))
    • Ensure storybook generates prop tables from TS
  • TypeScript types become bound by semver
    • Ensure stability of types via something like the public-api snapshot system
  • Proptypes become no longer bound by semver, overall provided on an "as-is" basis
    • Probably could still leave in the proptypes public api snapshot for visibility's-sake

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.

@elycheea
Copy link
Contributor Author

elycheea commented Apr 8, 2024

@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.

@matthewgallo
Copy link
Member

I'm wondering how or if our viewpoint on this changes at all when taking into consideration that prop-types is deprecated and will be officially removed in React 19 (more info here). Their before and after example from the React 19 upgrade guide shows only typescript types.

// 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.

@sstrubberg sstrubberg added type: enhancement 💡 New feature or request role: dev adopter: security Issues connected to work that accelerates IBM's Security offerings. adopter: data & ai Issues connected to work that accelerates IBM's Data & AI offerings. adopter: automation Issues connected to work that accelerates IBM's automation offerings. adopter: sustainability Issues connected to work that accelerates IBM's sustainability offerings. labels May 14, 2024
@wkeese
Copy link
Contributor

wkeese commented Jul 26, 2024

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.

@tay1orjones
Copy link
Member

@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.

@wkeese
Copy link
Contributor

wkeese commented Sep 24, 2024

@wkeese Production builds should use something like https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types to strip the proptypes.

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.)

@tay1orjones
Copy link
Member

Yeah, we can't strip them but we could wrap them in a __DEV__ check like we do in @carbon/icons-react so they'll be tree shaken/dead code eliminated. It might help us get to a flat entrypoint at some point, too - carbon-design-system/carbon#5442

@wkeese
Copy link
Contributor

wkeese commented Sep 26, 2024

Sounds good although I'm not actually sure what you mean by "flat entrypoint".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adopter: automation Issues connected to work that accelerates IBM's automation offerings. adopter: data & ai Issues connected to work that accelerates IBM's Data & AI offerings. adopter: security Issues connected to work that accelerates IBM's Security offerings. adopter: sustainability Issues connected to work that accelerates IBM's sustainability offerings. area: typescript role: dev type: enhancement 💡 New feature or request type: infrastructure 🤖 Issues related to devops, builds, packaging type: process 🎞️ Process and other project mgmt tasks or discussions type: question ❓ Further information is requested
Projects
Status: Icebox 🧊
Development

No branches or pull requests

5 participants