Skip to content

Commit fd341ad

Browse files
refactor(router-core): strip internal types from public build (#4907)
This PR proposes we use the `@internal` JSDoc tag, and `--stripInternal` typescript compiler option to remove internal keys from the public `.d.ts` files. Docs for `stripInternal`: https://www.typescriptlang.org/tsconfig/#stripInternal This helps ensuring internal values aren't considered as part of the *public API surface* by users, allowing us more flexibility in refactoring. > [!WARNING] > This PR proposes we add `stripInternal` to the entire repo, not just `router-core`. However there are already some values marked as internal that weren't added by this PR: > - `InferStructuralSharing` in `react-router` > - `handleHashScroll` in `router-core > scrollRestoration` > - many `InferFoo` types in `router-core > typePrimitives` > > as a result of this, we might have to switch some of those `@internal` tags to something else (like `@private` maybe?) because they are, in fact, necessary for the build to be correct. Example: ```ts export type Foo = { a: number, /** @internal */ b: number, } /** @internal */ export function hello() { return 'world' } export const answer = 42 ``` gets compiled as `.d.ts` to ```ts export type Foo = { a: number } export const answer = 42 ``` --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 3023706 commit fd341ad

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/router-core/src/Matches.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ export interface RouteMatch<
137137
searchError: unknown
138138
updatedAt: number
139139
loadPromise?: ControlledPromise<void>
140+
/** @internal */
140141
beforeLoadPromise?: ControlledPromise<void>
142+
/** @internal */
141143
loaderPromise?: ControlledPromise<void>
142144
loaderData?: TLoaderData
145+
/** @internal */
143146
__routeContext: Record<string, unknown>
147+
/** @internal */
144148
__beforeLoadContext?: Record<string, unknown>
145149
context: TAllContext
146150
search: TFullSearchSchema

packages/router-core/src/typePrimitives.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type ValidateParams<
3636
> = PathParamOptions<TRouter, TFrom, TTo>
3737

3838
/**
39-
* @internal
39+
* @private
4040
*/
4141
export type InferFrom<
4242
TOptions,
@@ -48,7 +48,7 @@ export type InferFrom<
4848
: TDefaultFrom
4949

5050
/**
51-
* @internal
51+
* @private
5252
*/
5353
export type InferTo<TOptions> = TOptions extends {
5454
to: infer TTo extends string
@@ -57,7 +57,7 @@ export type InferTo<TOptions> = TOptions extends {
5757
: undefined
5858

5959
/**
60-
* @internal
60+
* @private
6161
*/
6262
export type InferMaskTo<TOptions> = TOptions extends {
6363
mask: { to: infer TTo extends string }
@@ -131,7 +131,7 @@ export type ValidateId<
131131
> = ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>
132132

133133
/**
134-
* @internal
134+
* @private
135135
*/
136136
export type InferStrict<TOptions> = TOptions extends {
137137
strict: infer TStrict extends boolean
@@ -140,7 +140,7 @@ export type InferStrict<TOptions> = TOptions extends {
140140
: true
141141

142142
/**
143-
* @internal
143+
* @private
144144
*/
145145
export type InferShouldThrow<TOptions> = TOptions extends {
146146
shouldThrow: infer TShouldThrow extends boolean
@@ -149,7 +149,7 @@ export type InferShouldThrow<TOptions> = TOptions extends {
149149
: true
150150

151151
/**
152-
* @internal
152+
* @private
153153
*/
154154
export type InferSelected<TOptions> = TOptions extends {
155155
select: (...args: Array<any>) => infer TSelected

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"resolveJsonModule": true,
2222
"skipLibCheck": true,
2323
"strict": true,
24+
"stripInternal": true,
2425
"target": "ES2020"
2526
},
2627
"include": ["eslint.config.js", "prettier.config.js", "scripts"]

0 commit comments

Comments
 (0)