Premium Analytics: add explicit return types to Stats data hooks - #50037
Premium Analytics: add explicit return types to Stats data hooks#50037kangzj wants to merge 1 commit into
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
The Stats data hooks relied on TypeScript inference for their return types.
Write the contract out explicitly so consumers and reviewers can see what each
hook returns without tracing through the query/report helpers.
- Introduce an exported UseReportResult<TData> describing the report helper's
{ primary, comparison, hasComparison, ... } shape, and annotate useReport,
useStatsReport, useStatsQuery and useStatsAppQuery.
- Annotate every Stats hook: report hooks return UseReportResult<T>, query and
app-query hooks return UseQueryResult<T>, and the mutation hooks return
UseMutationResult<...>.
Pure typing change — each annotation matches the previously inferred type, so
there is no runtime or behavioural change.
da76fe6 to
e2ead6d
Compare
|
Closing — this was optional polish, not a fix. The Stats hook return types are already fully correct via TypeScript inference (a passing typecheck with the explicit annotations confirms each one matched the inferred type exactly), so call-site types are identical with or without it. Not worth the churn across ~30 files for the marginal drift-guard benefit. |
Fixes #
Proposed changes
Anyone calling a Premium Analytics Stats hook (
useStatsTopPosts,useStatsArchives,useStatsAppReferrersSpam, …) currently has to trace through the query/report helpers to find out what the hook returns, because the return types were left to TypeScript inference. This PR writes those contracts out explicitly so the return shape is visible at the call site and in editor tooltips, the same wayuseStatsEmailSummaryanduseStatsCommentFollowersalready do.UseReportResult< TData >describing the report helper's{ primary, comparison, hasComparison, isLoading, isFetching, hasData, isError, error, refetch }shape, and annotate the shared helpersuseReport,useStatsReport,useStatsQuery, anduseStatsAppQuery.UseReportResult< T >UseQueryResult< T >UseMutationResult< … >Each annotation matches the type TypeScript already inferred, so this is a pure typing change with no runtime or behavioural impact.
comment-followerswas already explicitly typed and is left untouched.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. Type-only change; no data, requests, or behaviour are affected.
Testing instructions
pnpm --dir projects/packages/premium-analytics run typecheck— passes (a clean typecheck is the proof that every explicit annotation matches the previously inferred type).pnpm exec eslint --max-warnings=0 projects/packages/premium-analytics/packages/data/src/hooks/*.ts— passes.