Finalizing the native TypeScript proposal

Hi folks! I’m back again with an update on the TypeScript proposal. Previously in the follow-up post I said that after two weeks we would make a decision about it. It’s been several months since then, so it’s about time to make that decision!

While there was some feedback to the proposal, nothing was raised that seemed to blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. the integration of native TypeScript into the GutenbergGutenberg The Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc. https://wordpress.org/gutenberg/ project. Indeed, some packages (like compose and components) have seen a great deal of native TypeScript introduced. In fact, compose today is fully typed and this would not be the case if it were not for native TypeScript support in Gutenberg.

Therefore, I’d like to officially announce that the Gutenberg project supports native TypeScript. We will continue to follow the guidelines laid out in the follow-up proposal, reproduced here for posterity.

For existing code:

  • The default is to use JavaScriptJavaScript JavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user’s browser. https://www.javascript.com/.
  • When it is possible to type something simply with JSDoc, use JSDoc
  • If there are complex types, but JSDoc is still sufficient generally for consuming those types, you may extract the complex types into a types-only types.ts file to be imported into the JSDoc
  • If it is not possible to express the types using JSDoc or if the JSDoc will vastly over-complicate the ability to type a function, convert it to TypeScript

For new code:

Use TypeScript when working in a “low-level package” (as defined below) for new code. Otherwise, follow the same pattern laid out for the existing code.

Low level packages:

A low level package is a package that:

  1. Provides a public APIAPI An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways.; and
  2. Is not frequently contributed to.

The coding guidelines for Gutenberg will be updated to reflect this approach to TypeScript.

#javascript