WordPress and Typescript #67781
Replies: 4 comments 11 replies
-
This would be the perfect opportunity to ask for a review of: 😄
Wondering if there's a non-complex way to exclude existing JS dirs while including new |
Beta Was this translation helpful? Give feedback.
-
Love and agree with practically everything here. To add: I was also initially in the anti-ts camp, but have come around in the last year or so. My primary original concerns were about the additional barriers of entry to contributing on a project that's already significantly disjoined from the rest of the WP project. I believe these concerns are mostly tempered as:
Disagree here - or rather I'd made a distinction between establishing best patterns and documenting them. E.g. changing |
Beta Was this translation helpful? Give feedback.
-
Could you please explain the reasons that made you change your mind, @youknowriad ? I think that would enrich the conversation around the proposal. |
Beta Was this translation helpful? Give feedback.
-
I really appreciate the idea of having everything typed. It simplifies learning the codebase, clarifies expectations, and helps identify potential issues faster. When I started working with Gutenberg, I found Dataviews the easiest to understand because there was no guesswork when examining a small portion of the code. The types made it clear what functions or components expected, making navigation and comprehension much smoother. Regarding the trade-off As a new developer, I believe most people will get comfortable with TypeScript fairly quickly and appreciate the time it saves when diagnosing issues. Given the growing popularity of TypeScript and its widespread adoption alongside frameworks like Next.js, there is ample support and extensive documentation available to help developers understand the codebase and overcome any learning challenges. Lastly, |
Beta Was this translation helpful? Give feedback.
-
We've introduced Typescript in WordPress packages for over 3 years now. Core contributors are now more familiar with the language and have formed a better opinion on it, our last official statement on Typescript usage in WordPress is now a bit outdated. It is time to consider our usage of TypeScript again, better document our approach to TypeScript, any guidelines... Hopefully, after we discuss this a little bit, we make an update to our documentation and publish a make/core P2 post summarizing the decisions.
State of packages:
*.ts
files and some old code style rely on TS in JSDocs.Personal perspective:
I've long been very reticent towards TypeScript, I've always seen its value when it comes to define structures (think DataViews API, Block API...) but less when it comes to components props (especially when there's multiple level of component abstractions: spreading props down multiple levels).
That said, as I started to get more and more familiar and embrace it more in the project per the previous proposals, I've changed my mind a lot. I know think that it's actually valuable for any package and would encourage its usage more broadly.
Proposal
Based on this, I would like to propose that we start thinking about our next steps here with the goal of: Increasing our typescript coverage at a higher pace.
The approach I'm proposing is the following:
*.ts
files should be typed and checked in these packages while*.js
shouldn't. We can achieve this simply by setting"checkJs": false
intsconfig.json
. This allows a slow but consistent migration to typescript as we iterate on existing packages.@ts-expect-error
. If it's a high number of untyped imports, it's probably not the right moment to type the file we're working on.In parallel to that proposal, there's some work to be done to better guide developers writing TypeScript for WordPress. Better Typescript documentation in the context of the project. Things like: Any or unknown, interface or type, Centralized types.ts file per package or not.
(I don't think this last part of the proposal, the documentation aspect, deserves a lot of discussion, this discussion can happen directly in the PR adding the docs. We just need a champion there to lead the documentation efforts)
cc @WordPress/gutenberg-core
Beta Was this translation helpful? Give feedback.
All reactions