You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While Gutenberg packages are not authored in TypeScript, we can still benefit from its JavaScript type checking using the JSDoc we already write. This will bring us some benefit of type safety, even as we continue to write modules with JavaScript, not TypeScript.
Progress:
All of our modules are to be opted-in to type checking. The progress thus far:
For single files, you can also include a // @ts-check line at the top of the file. You should use this line when temporarily testing the impact of type checking, or if you are working to convert a very large package one file at a time.
The build:package-types npm script will be run as part of precommit, which handles type checking. It can be very helpful to watch the types build and work through issues surfaced by the compiler as you add types. To watch the types build, run:
npm run build:package-types -- --watch
You may also need to improve existing JSDoc, as it was written based on assumed usage. Type checking will enforce its validity, and in many cases our JSDoc is invalid.
Previously: #17014
While Gutenberg packages are not authored in TypeScript, we can still benefit from its JavaScript type checking using the JSDoc we already write. This will bring us some benefit of type safety, even as we continue to write modules with JavaScript, not TypeScript.
Progress:
All of our modules are to be opted-in to type checking. The progress thus far:
Compose: Add types #21580Compose: Add types (progressively) #27344)Guidelines:
See the packages README for details on TypeScript usage. In summary, a package can opt-in by following these steps:
tsconfig.jsonto the package root. The@wordpress/i18npackage has a good example of a basic config."types": "build-types"to the package'spackage.jsonso that consumers will pick up the published types from the package.tsconfig.jsonreferences.For single files, you can also include a
// @ts-checkline at the top of the file. You should use this line when temporarily testing the impact of type checking, or if you are working to convert a very large package one file at a time.The
build:package-typesnpm script will be run as part of precommit, which handles type checking. It can be very helpful to watch the types build and work through issues surfaced by the compiler as you add types. To watch the types build, run:You may also need to improve existing JSDoc, as it was written based on assumed usage. Type checking will enforce its validity, and in many cases our JSDoc is invalid.
For syntax and usage, reference: