-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Testing: Add TypeScript types validation for modules #18838
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@dsifford Yes, definitely, I think for WordPress dependencies we should aim for what you propose. There was some previous related discussion to this:
|
Yep, that |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Closing this out as the work has either been completed or is no longer relevant. Happy to reopen if we need to but, at this point, a new issue is likely best. |
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.json
to the package root. The@wordpress/i18n
package has a good example of a basic config."types": "build-types"
to the package'spackage.json
so that consumers will pick up the published types from the package.tsconfig.json
references
.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: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:
The text was updated successfully, but these errors were encountered: