Add Router type export to @wordpress/route#76139
Conversation
Pick the curated surface area from the underlying router so consumers can type the router instance without importing from @tanstack/react-router directly.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 6.89 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 20faa1f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22957355972
|
There was a problem hiding this comment.
Pull request overview
Exports a public Router type from @wordpress/route so downstream consumers can type router instances without reaching into @tanstack/react-router internals.
Changes:
- Add
packages/route/src/types.tsdefining a curatedRoutertype viaPick<AnyRouter, ...>. - Re-export the
Routertype frompackages/route/src/index.ts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/route/src/types.ts | Introduces the curated public Router type based on AnyRouter. |
| packages/route/src/index.ts | Re-exports Router from the package entrypoint for consumer access. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/route/src/index.ts
Outdated
| * Internal dependencies | ||
| */ | ||
| export { privateApis } from './private-apis'; | ||
| export type { Router } from './types'; |
There was a problem hiding this comment.
Is there a particular reason why we should not export all the types available?
I would do this:
export type * from '@tanstack/react-router';
There was a problem hiding this comment.
I'm following the idea behind this package: exposing a list of public and private resources, and I believe the exposed types should align with them.
react-router probably exposes many types that we wouldn't like to transit beyond this package.
There was a problem hiding this comment.
Types are not runtime values, so I don’t think we need to worry about breaking changes in this case. I’m concerned that exporting only some types could lead to unnecessary “typo gymnastics,” which I find inconvenient as a developer.
There was a problem hiding this comment.
I'm okay with exposing all types.
There was a problem hiding this comment.
Thinking carefully, I believe we should now follow the package's instructions. The index already has a set of types to export.
Remove separate types.ts file, define Router as Pick<AnyRouter> directly in index.ts with documentation explaining the curated surface area and derived type patterns.
packages/route/src/index.ts
Outdated
| export type Router = Pick< | ||
| AnyRouter, | ||
| 'state' | 'navigate' | 'subscribe' | 'invalidate' | 'options' | 'history' | ||
| >; | ||
|
|
There was a problem hiding this comment.
Sorry for being late. I don't want to block this PR. What do you think if we export AnyRouter instead of customize it?
What
Exports a curated
Routertype from@wordpress/routeso consumers can type router instances without depending on internal implementation details.Why
Consumers of
@wordpress/routecurrently lack a public type for the router instance.This forces them to either use
any, import internal types from@tanstack/react-routerdirectly, or duplicate type definitions.A curated
Routertype provides a stable, narrow contract that decouples consumers from the underlying router library.How
packages/route/src/types.tswith aRoutertype that picks a curated set of properties (state,navigate,subscribe,invalidate,options,history) fromAnyRouterRoutertype frompackages/route/src/index.tsTesting
npm run build -- --include=routeRoutertype is available viaimport type { Router } from '@wordpress/route'