Fix typing of defaults and each() for the JavaScript ExtensionHook.
Review Request #14568 — Created Aug. 21, 2025 and updated
Djblets.ExtensionHook
has two issues that make it difficult to build
and use hook implementations.The first is that
defaults
was a hard-codedExtensionHookAttrs
,
rather than aPartial<ExtensionHookAttrs>
, which means that any
subclass must also include everything inExtensionHookAttrs
in their
defaults
. This isn't necessary with Spina, which will merge the
dictionaries together. By switching toPartial<...>
, 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 asExtensionHook
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 |
---|---|
4dd7501d81c944282f111e6edadeab6cfb97fad3 |