-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[RFC] TypeScript migration #2479
Comments
Thanks @vpicone for writing this up! For full TypeScript conversion I'd like careful observation on the learning curve of our developers/contributors. Though there are extra efforts to get |
@asudoh the issues I see with that approach are:
The DefinitelyTyped types I published for @carbon/elements are a perfect example. After my initial commit, they've fallen out of sync very quickly. For the learning curve, the typescript onboarding difficulty depends largely on the strictness of the rules, as just regular Out of sync types could cause more harm than good for end users and actually end up costing dev time in the end, rather than saving it. |
That said I believe Material-UI is using internal .d.ts files, so could be a good example of that the hand written types method. |
Wrt learning curve - Another problem I'd like careful look at is getting more people onboard to our development, to better serve our users for the various kind of problems in our backlog. Would like to see a good balance between solving TS problems vs. solving other problems. |
With the rules being progressively more strict, solving TS problems would be solving JS problems as well as preventing future issues. For example, the modal trap just recently ended up causing even more problems than it solved. The undefined issue we shipped that broke the modal never would have been prevented with typescript. That issue remained broken for quite a bit and cost significant dev time for review. That time could have been spent on the backlog. While we might be introducing friction for contributors unfamiliar with typescript, I think that types would allow contributors to work more confidently in complex components and more quickly orient themselves in the code base. It also allows us to be more confident that their changes aren’t breaking. In my opinion, the types already exist, they’re just in our mental modal of the project. Typescript allows us to formalize them for new and existing contributors. |
thanks @vpicone for drafting this RFC! I'm excited to potentially introduce TS into our project and have been looking to for a bit now. As @asudoh mentioned, we need to carefully weigh the cost and benefits to justify the investment into TS. That being said, I am all for this initiative. on a side note I agree that TS would have helped prevent a lot of the headaches that introducing the modal focus trap caused, but I think part of that may have stemmed from adding dependencies without fully vetting them, which is why this RFC and discussion is so crucial! |
Couple of initial questions that I have when we think of TypeScript integration:
|
@joshblack if the feature changes the syntax significantly, we'd need to use a babel macro until the language feature is supported by typescript (level 3+). Otherwise, all the standard plugins would work. As an example, object rest/spread wasn't typescript supported for quite some time and folks would include the babel plugin. TS definitely isn't a drop in replacement for prop-types, especially for libraries that are consumed by JS projects like ours, since it disappears at run time. Typescript will throw an error if the prop-types and Prop types don't map: Also, there's a babel plugin to set prop-types from typescript types. If we wanted to automate the process of generating them. |
Hi there! 👋 If you're wondering why this issue was moved, we're currently updating our repo structure so that every package is found in the same project. This should not have any impact for you, but we wanted to give you a heads up in case you were wondering what is going on. If you have any questions, feel free to reach out to us on Slack or contact us at: [email protected]. Thanks! |
We've marked this issue as stale because there hasn't been any activity for a couple of weeks. If there's no further activity on this issue in the next three days then we'll close it. You can keep the conversation going with just a short comment. Thanks for your contributions. |
NOT STALE |
We've marked this issue as stale because there hasn't been any activity for a couple of weeks. If there's no further activity on this issue in the next three days then we'll close it. You can keep the conversation going with just a short comment. Thanks for your contributions. |
As there's been no activity since this issue was marked as stale, we are auto-closing it. |
Just wanted to mention my support for moving to typescript! Our team also uses typescript, and of course I would love having types when using carbon.... But also I think in the long run switching to typescript will improve the quality of the carbon code... Our team also struggled with the decision to decide whether or not to adopt typescript, whether it was worth the effort for our developers to deal with the extra overhead of learning typescript and typing everything, but overall I think everyone on our team is now happy that we did it. Of course there's some times still when we are struggling with the typing even though the code itself works, and some times where there can be bugs that typescript didn't catch because the types are only as good as you make them... But it has allowed us to be a lot more confident in doing refactorings, and allowed us to confidently make some big changes and improvements to our codebase that we were usually too timid to do before... |
Totally agree, even in partially implementing typescript I found some issues that I wouldn’t have detected otherwise. I feel like for a top level component library those sorts of issues should be air tight. |
Here to voice my support for TypeScript typings for Carbon. I work on a team within IBM with a codebase written almost entirely in TypeScript. With the big push for us to adopt the new Carbon/IDL styles into our product, it's been a really hard decision for us to pull in the Inclusion of a full suite of TS typings into the official codebase (or through definitely typed) would be a huge boon to my team, and I'm sure several others that are looking to adopt Carbon. |
Moved my typings to a definitelytyped PR: DefinitelyTyped/DefinitelyTyped#37442 |
We've marked this issue as stale because there hasn't been any activity for a couple of weeks. If there's no further activity on this issue in the next three days then we'll close it. You can keep the conversation going with just a short comment. Thanks for your contributions. |
As there's been no activity since this issue was marked as stale, we are auto-closing it. |
Do you have any updates on this? I think moving into TS will really improve the developer experience, including your own. |
Summary
TypeScript is a superset of Javascript – all Javascript is valid Typescript. However, once a project has typescript enabled, you can annotate your code to provide type hints to your users and other developers.
Just as shared styles between Carbon frameworks improves user experience, so to would shared behavior. Typesafety allows us to ship components that perform and behave as expected.
Related issues: #1296, #727, #1103, #580
Motivation
End users, product developers, as well as Carbon developers would all benefit from the addition of type safety to Carbon products
Uncaught TypeError(Cannot read x of undefined
or spelling errors means more time on real issues.null
andundefined
guards means more resiliant APIs– Alerted to misuse of props, state, third-party library, and dom errors while writing your code.
Design
There are currently to main ways to compile typescript into javascript(the typescript compiler, and through babel. Since our project is already using Babel, switching to typescript would be unnecessary.
Namespaces and const enums are not supported by the babel compilation, however, this can be mitigated with compiler configuration.
As we look toward migrating codebases to a mono-repo, typesafety will offer a means to share types between projects and permit large scale refactors with confidence.
Drawbacks
Alternatives
Non-Typescript
TypeScript without migration
These solutions offer some of the benefits of TypeScript types with different drawbacks. While the core library would still be standard JavaScript maintaining types would be a manual effort.
The main issue with these strategies is that they require a much more manual effort up front and the types would be of lower quality than those generated natively from the project in situ.
Definitely-typed
Internal
.d.ts
filesAdoption strategy
At no point will typescript migration stop or prevent work on the project. TypeScript can get out of the way when necessary (
@ts-ignore
andany
orunknown
types). It will never break builds unless we chose to enable that behavior.While each of the Carbon javascript projects would benefit from the addition of types. I believe the most valuable library at this time would be carbon components react (CCR).
Since we already have some run-time type checking through
prop-types
, we already have a starting point. In addition, thanks toprop-types
CCR developers are already at least slightly familiar with the constraints imposed by types.Conversion path
A – Just rename everything to
.ts
and.tsx
The first pass at converting the project will rename the files and add babel, storybook, and jest configuration to handle these new file types.
The initial config will have the loosest possible config. Separate PR's will be made to turn on each of the strict-mode rules separately resolving issues as they come up.
Any objective errors uncovered as a result of the conversion will be resolved as part of the same PR.
Prop types will be defined at the same level of specificity as the
prop-types
. No unnecessary types added.Types can be shipped from day one
B – Leave the files as
.js
config enableallowJS
andcheckJS
.ts
.ts
.js
files are converted to TypeScriptMigration stories from others
The text was updated successfully, but these errors were encountered: