-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Migrate to TypeScript #15984
Comments
@cyberhck What do you expect for with such migration, as a user of Material-UI? My counter-argument is with the opportunity cost it creates for us when committing with this effort. What else can we work on? From my perspective, the priorities are: 1. More components (more time saving) 2. Isolate the styling solution, have JSS has optional, make styled-components the default engine (broader reach). Do we have room for any other major effort? |
How did you come to this conclusion? |
I think I might have given the wrong impression on my issue, please let me clarify In no way I wish to pause the feature development for material UI and only work on typescript migration, I'd never ask any project to pause their own development. Then there'd be no v5 release, release without any new feature doesn't make any sense. currently we're maintaining javascript files, and keeping definition files on the side, which may not be in sync all the time, and they might not reflect the true types, changing one js file and forgetting to change type definition might also be a problem or rushing through changing a component but forgetting to update types might also be a real problem, That's what I meant when I said maintaining separately doesn't seem to be ideal. The way I proposed to do is the following, Say there's a bug fix for button or (someone interested from community), will start working on migrating that 1 component and make sure the tests pass (without converting tests to typescript initially), once the button is merged, we can come back to tests later to convert those as well. This way you keep your development steady, and if you're touching some component any way, then you can convert that particular component into typescript because we already have so many components with good type definition, it should be easy to convert components one by one.
As a user of material-ui I might not be getting very tiny benefit where I can be confident that the typedefinition provided are actually in sync with project (because code is source of truth), but I'd argue benefits which will indirectly influence me. after the migration is done, the codebase might have less potential problems and development might be a bit faster, I could contribute more easily if I wanted to. It's more of a confidence thing I guess. |
@oliviertassinari sharing something from Jest migration to TypeScript experience.
The 3rd bullet point stopped me completely from actually giving you a hand, I tried to migrate Be prepare, do not hunt the perfect typespec, sometimes a simple I am more than happy to help you, but since I tried this myself, I know I will require some support from the Core team. |
The problem is not converting JavaScript to TypeScript. The problem consists of many issues of TypeScript in the JSX domain. We would need to Yes sometimes types are outdated but that's usually just a missing prop or CSS class key. It's very rare that those stay unfixed for more than one patch version. Then we have to migrate all the internal tooling: lint, mocha test, karma vrtest etc. This is nowadays less of a hassle thanks to Which leads to the last point: Not every maintainer has experience with typescript. And this may be egoistic but I don't want to be the guy that has to review every PR because there's some issue with TypeScript. I like that we have the ability to move implementation and and interface separately which is what TypeScript is for us now: A interface description. Bugs that could've been caught by TypeScript are very rare as far as I can tell (didn't investigate this; just a feeling I have). So far I could only identify that we would eliminate issues regarding outdated props. I don't think that justifies the amount of effort involved. |
@eps1lon being a TypeScript user myself this is my pain https://github.com/straw-hat-team/react-admin/blob/1352d6c56d777e094febd652472d5dadf7387fe8/src/administrator/AppBar.tsx#L15 I keep adding,
Keep it like that then, you don't have to use strict rules and force yourself to do things that are almost no value, this is one thing I am trying to explain to people, there is nothing wrong with You would argue the value of TypeScript then, but I would say that I would prefer to have correct typespec than having all the typespec. I don't believe that we should be using TypeScript for capturing bugs, but I would encourage for documentation, faster understanding of the internals since you have more static types that you could analyze. Use it when you need it 🤷♂ |
The issue you linked it not caused by an outdated type spec. I would encourage you to submit issues or search through them or read the docs. As a typescript user you should be aware that the error messages are not always helpful i.e. point in the right direction. |
I agree with @eps1lon, I think that we would be better off (from a fundamental point of view) completing #14897 and spending our time of the existing reported TypeScript issues before even considering a migration of the codebase to TypeScript. The main value I see in a TypeScript migration is a marketing one. We can turn the users' psychology in our favor without changing the core product value. It works as follow: "the codebase is written in TypeScript, it must have great support, let's use this library. Oh, there is a bug here, well it must be a bug in TypeScript itself or this library that doesn't use TypeScript, not Material-UI". |
I believe 1. demos in typescript, then 2. tests migrated to typescript would yield the biggest benefit. Moving the source files there would be great from a ts-user standpoint (and generally understanding the codebase), but I also understand the non-ts user perspective so I am not strongly advocating either way. Certainly my personal perspective is pro-ts. I do believe that tests in ts/tsx would very much help surface ts issues, similar to getting demos to ts/tsx. |
That is work that's up for grabs. You can add a |
I'd rather try changing to tsx and add the |
What would be the benefit of that? |
Builds with Babel and type checking with tsc? |
We get type checking by adding |
We are already running
so it is not an additional build step but an existing one. Further, are people more likely to know jsdoc(?) annotations or typescript annotations? |
the jsdoc annotations are parsed by typescript just as regular typescript types. There's no difference there.
I thought we were talking about our unit tests. It's not strictly speaking a new build step but an additional preset that has to be configured.
Yes I know our CI setup quite well considering I build most of steps concerned with type checking. To further clarify: That step already type checks |
I'm not sure how I get the sense that things like #16315 would more likely be surfaced by quite simply switching tests to I'm not sure doing something non-standard makes sense. Either we go towards ts, or not. My preference is clear that moving tests to tsx would be a positive:
|
Everyone knows we can easily do a partial migration and move slowly, but if maintainers don't want to give TypeScript a try, simply listing benefits won't do anything. As some of us already said we'll help migrate and do a gradual migration. I'm getting sense that they just don't want to do it. There's no point on arguing benefits or tradeoffs. Issue title clearly says for v5 which means you can have breaking changes, some fixes which needs to be made for typescript can be done as a breaking change, and once we pass the initial friction, migrating the rest should be very easy. You don't have to turn on all the strict rules initially, you can get there gradually. Arguing over things is just waste of time, I think the original request was we're willing to help, are you interested? |
Sure. You can add |
The point was to start doing actual conversion, without only using |
I thought adding |
no, if you were to change extensions, you can inline your type definition, you can't have a javascript file like this: const something = (): boolean => {
return true;
} If we start moving everything to proper typescript, the type checking will also increase, and will find potential bugs. I'm advocating the complete move to typescript, not just type checking, which includes build system, linting and what not. |
Yeah I don't understand what's being proposed here. We are increasing our type coverage, we are using tslint. If the argument for ts extension is only a stylistic one then I think we don't have to put effort into it. Also advocating for a move to linting with typescript (I guess you mean tslint?) is backwards. tslint will soon be deprecated. If anything we should look into moving to eslint 6 (released yesterday) and how we deal with I would appreciate if the people arguing for a typescript migration would familiarize themselves with the codebase (I'm always eager to answer question and to get more people to contribute to the ts related code) before making such strong statements here. It's easy for outside readers to get the impression that we don't test our types. Maybe something is lost in translation but I still don't understand what the difference in type checking is between |
Maybe I missed something, on your JS files, can you show me an instance, where you define a return type? About the migrating to tslint, I understand your position, tslint isn't getting deprecated tomorrow, and we can always switch to eslint-typescript instead. Changing extension is about the cognitive load when I read your js files, I don't exactly know what type your function is supposed to get by looking at your code, I've to open yet another file just to do that, When I'm contributing, having ts files and having parameter type, return types right there gives me a knowledge of what's supposed to happen. And also can you also mention what'd be the downside of changing the extension to tsx/ts if you're so sure with Like in my previous comment, you can't have a js file like this: const something = (): boolean => {
return true;
} if it were a ts file, just by looking at code, I know I'm supposed to return a boolean |
@eps1lon I am annoyed by that person, laughing at your response because it got under your skin, and also worry about you because you let that happen. We love, cheer up, and support you. Having patience, and understanding people's emotions are the cost of popularity and OSS. I want you and OSS maintainers to be happy. But we can't do anything about these situations other than understanding their childish and emotional behaviors and focus on what matter. We signed off for these comments, please don't let this affect you. |
An update on our progress toward TypeScript What we have done
Observations
What we are working onImproving our component infrastructure to support sources in TypeScript. For instance #21758.
Future?
At this point, it doesn't seem that we need to willingly dedicate time to the problem. TypeScript is organically gaining usage in our codebase. It seems that we can sleep on it, and focus on other problems 🤔. |
This could be a way to validate the experience of the typespec but can get really annoyed and full of
I wouldn't, TypeScript has a cost, and most developers out there are not being taught in TypeScript as the first language. Personally, has been few years in TypeScript and I know I am not the norm (compared with the entire Front End ecosystem not just React) so I don't mind toggling. That being said, use local storage, and save the configuration there, most likely if I switched is because I am interested in TypeScript over JavaScript.
Is there any process on wich I could find the series of steps to convert the codebase or help in any way? I haven't look much but having a process that you could share with everyone outside the core team could open the door for more streamed line collaboration. |
I believe that we all want to build the best and most reliable set of react components ever written. As part of the core team today, we now have 2 big components written in typescript, date-pickers and the data-grid. Therefore it seems to me that now would be the right time to handle the pain and migrate every component in core and lab to typescript. Also Typescript is very well supported by all the tools we use and it's pretty mature now, so the risk is limited. |
@yordis Agree, I think that we can reevaluate this TS vs JS demo default decision in one year, with the 2021 developer survey results and with how the usage of the TypeScript demos grows. Yes, the choice of TypeScript vs JavaScript demos is persisted between sessions on the documentation, with a cookie: 15% (TS) vs 75% (JS).
We don't have any steps to perform the migration as we don't have any components yet fully written in TypeScript in the core infrastructure. The challenges that are left to be solved for doing such, cc @dmtrKovalenko:
Once we have that, we can do the migration as a background task, and ideally engage the community to do it, I have no doubt they will be happy to help, so the core team might just have to focus on reviewing migration pull requests from the community. During the JavaScript demos to TypeScript demos migration era, I believe the majority of the migration was done by the community, once Sebastian put the infrastructure in place to support it.
@dtassone We have discussed this a bit in the past, at this point, for instance, if we look at the current open TypeScript issues or the problem we face, or even what people ask from us in the user-survey, the value of migration to TypeScript wouldn't be most about its intrinsic value but more about the perceived one by the community, where people wrongly approximate written in TypeScript with great to be used in a TypeScript codebase and higher code quality (I would argue that higher code quality is not strongly correlated, especially when we add defensive logic instead of @ts-ignore). At this point, I think that the main incentive we can have for migration to TypeScript is:
IMHO this wouldn't be the best option. I think that we should only do "big bang" when no other progressive approaches are sustainable. In this case, we are lucky to have TypeScript as an optional enhancement, that we can deploy progressively, so should we. What do you have in mind with "ditch"? Going back to the marketing value, there is one metric we might want to optimize for, this one: GitHub determines the % by looking at the number of files, no matter how many lines there are (at least it seems). We have 8792 JavaScript files and 472 TypeScript files. So TypeScript is 5% (=472/(8792+472)). However, if you look closer, you will find that among all these JavaScript files there are 6578 generated icons, which are very small files and arguably we could consider having them written in TypeScript as there are generated types definitions and type tests. For instance, with this diff, using https://github.com/github/linguist: diff --git a/packages/material-ui-icons/src/.gitattributes b/packages/material-ui-icons/src/.gitattributes
new file mode 100644
index 000000000..282f21f32
--- /dev/null
+++ b/packages/material-ui-icons/src/.gitattributes
@@ -0,0 +1 @@
+*.js linguist-language=TypeScript we would go up to: which seems more accurate to the state of the codebase. Thoughts? |
If you think about it there is no point in being progressive on this one. It's not like converging towards a certain API |
@dtassone What's the smallest unit of codes we can incrementally migrate? I believe it's each .js file, individually, the ones that are behind each .d.ts file. So, we should be able to migrate each file one after the other. Considering we have over 100 d.ts files, I would expect that we can do the TypeScript migration with over 100 iterations (pull requests), iterations we can empower the community with.
Taking a step back, I think that progressiveness should be our default answers to problems until we see strong values for not applying it. The value of progressiveness or working with small iterations is about all about: shorter feedback loop (the most important IMHO, to hit reality as fast as possible), delivering value to production more often, more flexibility. A core principle of Agile software development. I don't fully understand the problem you are referring to by maintaining different build steps during the transition. Do you have more details? I don't see what needs to be maintained.
I don't see the direct link between the TypeScript migration and the build step. Shouldn't we discuss the two individually? Do you want to open a new issue? Maybe you would like to engage in #18447? |
Since migration of core components to TS isn't a priority right now, further discussion is somewhat moot; so I'd rather we didn't spend more time on it. |
This comment has been minimized.
This comment has been minimized.
If we go back to the user-survey of 2020, we have almost half the respondents that mention using TypeScript, we also have "TypeScript integration" ranking at position 4 in the question: What are your key criteria when choosing a UI library? So the broader TypeScript topic is important (I'm not saying that migration is important, current metrics suggest it shouldn't be in the top of our priorities). Should we close this issue?
|
I had unsubscribed from this issue, but wow, a lot has changed since I first asked for this. I didn't even think this many people would be favoring migration to TypeScript. For the people who just want the typing, I believe the current state of typing provided is very good, and more and more codebase is being written in TypeScript, so this definitely has good TypeScript support. I want to state one more time, the issue was created in spirit of helping maintainers and new contributors, the end users already have it pretty good (except there's more possibility of having typing bugs, but that barely happens and when it does, creating one issue is all it takes for maintainers to fix it) I do want to add a few things which got lost in conversation.
Huge thanks to @eps1lon for his contribution :) |
Hello, guys Airbnb just released a new tool for migration huge javascript basis to typescript: Couldn't this help with the migration? |
Not really since the little nuances that this tool doesn't cover are why we wouldn't gain anything from the migration. |
We have the infrastructure in place to write modules and tests in TypeScript and already have some tests and modules (public and private) written in TypeScript and we'll continue porting JS files to TypeScript where appropriate. Components are not considered appropriate currently. On one hand because we don't think writing components in TypeScript solves an actual issue. If you disagree please refer to an existing issue (and we'll try to resolve it separately) or open a new one. This keeps the discussion focused. On the other hand TypeScript has some limitations that make this task hard. I've created a playground with a minimal component written in JS. If you're able to convert it to TypeScript please let us know. Changing type-tests is reasonable if a strong argument is made for your implementation. Playground: Minimal Material-UI component in TypeScript base |
@oliviertassinari @eps1lon can you assign a beginner friendly component to me? |
@akashshyamdev We can't. So far, we don't work on TypeScript migration for the sake of it. Instead, we wait for natural adoption, writing new modules in TS or when we need to touch a specific area of the codebase. I think that once the adoption rate it really high, like 80%, then we could give it a final push, only to get a consistent experience when developing in the codebase (always TS). |
In light of the issue's description: I think we are good, TypeScript is pretty much integrated now. And the last example for this is #41073 moving from prop-types naming conventions to TypeScript for the API docs. Now, it's about making sure any new modules continues to be written in TypeScript and we occasionally migrate JavaScript files to TypeScript anytime we feel the need for it. |
Hi according to roadmap, there'd be a possibility of discussion for migrating to typescript, as currently maintaining separately doesn't seem to be ideal, migrating the whole project into typescript would mean a huge task, but that'd make project much more maintainable.
Any plans on that front?
Edit by maintainers. We are progressively moving the codebase to TypeScript, as we write new modules or refactor existing ones. This started in 2019 and will likely take a while (and expected to), see this timeline:
The text was updated successfully, but these errors were encountered: