Skip to content
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

Closed
27 of 75 tasks
aduth opened this issue Nov 30, 2019 · 10 comments
Closed
27 of 75 tasks

Testing: Add TypeScript types validation for modules #18838

aduth opened this issue Nov 30, 2019 · 10 comments
Labels
npm Packages Related to npm packages [Status] In Progress Tracking issues with work in progress [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects

Comments

@aduth
Copy link
Member

aduth commented Nov 30, 2019

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:

Guidelines:

See the packages README for details on TypeScript usage. In summary, a package can opt-in by following these steps:

  • Add a tsconfig.json to the package root. The @wordpress/i18n package has a good example of a basic config.
  • Add "types": "build-types" to the package's package.json so that consumers will pick up the published types from the package.
  • Add the package to the root 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:

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.

For syntax and usage, reference:

@aduth aduth added [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. labels Nov 30, 2019
@aduth

This comment has been minimized.

@dsifford

This comment has been minimized.

@aduth
Copy link
Member Author

aduth commented Dec 2, 2019

@dsifford Yes, definitely, I think for WordPress dependencies we should aim for what you propose.

There was some previous related discussion to this:

@dsifford
Copy link
Contributor

dsifford commented Dec 2, 2019

Yep, that --declaration flag is a pretty big game-changer. Though, the types still won't be quite as good as those written in typescript due to limited support for generics and overloads.

@sirreal

This comment has been minimized.

@aduth

This comment has been minimized.

@annezazu
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Packages Related to npm packages [Status] In Progress Tracking issues with work in progress [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
No open projects
Core JS
  
In progress
Development

No branches or pull requests

6 participants