Fix typing of defaults and each() for the JavaScript ExtensionHook.

Review Request #14568 — Created Aug. 21, 2025 and submitted

Information

Djblets
release-5.x

Reviewers

Djblets.ExtensionHook has two issues that make it difficult to build
and use hook implementations.

The first is that defaults was a hard-coded ExtensionHookAttrs,
rather than a Partial<ExtensionHookAttrs>, which means that any
subclass must also include everything in ExtensionHookAttrs in their
defaults. This isn't necessary with Spina, which will merge the
dictionaries together. By switching to Partial<...>, subclasses can
type their own using their own attributes and rely on parent class
defaults.

The second issue is that ExtensionHook.each(), meant to iterate
through all instances of a hook for a given hook point, typed the hook
being passed to the callback as ExtensionHook and not as the subclass.
This forced callers to re-type, which was annoying. Now, we use generics
to reflect the specific subclass.

Unit tests pass.

Tested this with in-progress code in Review Board, verifying that the
typing was correct.

Summary ID
Fix typing of defaults and each() for the JavaScript ExtensionHook.
`Djblets.ExtensionHook` has two issues that make it difficult to build and use hook implementations. The first is that `defaults` was a hard-coded `ExtensionHookAttrs`, rather than a Partial<ExtensionHookAttrs>`, which means that any subclass must also include everything in `ExtensionHookAttrs` in their `defaults`. This isn't necessary with Spina, which will merge the dictionaries together. By switching to `Partial<...>`, subclasses can type their own using their own attributes and rely on parent class defaults. The second issue is that `ExtensionHook.each()`, meant to iterate through all instances of a hook for a given hook point, typed the hook being passed to the callback as `ExtensionHook` and not as the subclass. This forced callers to re-type, which was annoying. Now, we use generics to reflect the specific subclass.
4dd7501d81c944282f111e6edadeab6cfb97fad3
david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.x (5c82197)