Skip to content

Commit 3675b05

Browse files
committed
refactor: remove RouteRecordNameGeneric
1 parent 958a1ad commit 3675b05

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

packages/router/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export type {
115115
// route records
116116
RouteRecordInfo,
117117
RouteRecordName,
118-
RouteRecordNameGeneric,
119118
_RouteRecordProps,
120119
RouteRecordRedirectOption,
121120

packages/router/src/router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import type {
1010
RouteLocation,
1111
RouteLocationRaw,
12-
RouteRecordName,
1312
RouteParams,
1413
RouteLocationNormalized,
1514
RouteLocationNormalizedLoaded,
@@ -19,6 +18,7 @@ import type {
1918
RouteLocationAsRelative,
2019
RouteLocationAsPath,
2120
RouteLocationAsString,
21+
RouteRecordName,
2222
} from './typed-routes'
2323
import { RouterHistory, HistoryState, NavigationType } from './history/common'
2424
import {
@@ -212,6 +212,7 @@ export interface Router {
212212
* @param route - Route Record to add
213213
*/
214214
addRoute(
215+
// NOTE: RouteRecordName could be `keyof RouteMap` but the point of dynamic routes is not knowing the routes at build
215216
parentName: NonNullable<RouteRecordName>,
216217
route: RouteRecordRaw
217218
): () => void
@@ -226,7 +227,7 @@ export interface Router {
226227
*
227228
* @param name - Name of the route to remove
228229
*/
229-
removeRoute(name: RouteRecordName): void
230+
removeRoute(name: NonNullable<RouteRecordName>): void
230231
/**
231232
* Checks if a route with a given name exists
232233
*

packages/router/src/typed-routes/route-location.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { _LiteralUnion } from '../types/utils'
1111
import type { RouteMap, RouteMapGeneric } from './route-map'
1212
import type { Router } from '../router'
1313
import type { RouteRecord, RouteRecordNormalized } from '../matcher/types'
14-
import type { RouteRecordName, RouteRecordNameGeneric } from './route-records'
14+
import type { RouteRecordName } from './route-records'
1515

1616
/**
1717
* Generic version of {@link RouteLocation}. It is used when no {@link RouteMap} is provided.
@@ -49,7 +49,7 @@ export type RouteLocationTypedList<
4949
* Generic version of {@link RouteLocationNormalized} that is used when no {@link RouteMap} is provided.
5050
*/
5151
export interface RouteLocationNormalizedGeneric extends _RouteLocationBase {
52-
name: RouteRecordNameGeneric
52+
name: RouteRecordName
5353
params: RouteParamsGeneric
5454
/**
5555
* Array of {@link RouteRecordNormalized}

packages/router/src/typed-routes/route-records.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
RouteLocationNormalized,
44
RouteLocationRaw,
55
} from './route-location'
6-
import type { RouteMap, RouteMapGeneric } from './route-map'
6+
import type { RouteMap } from './route-map'
77

88
/**
99
* @internal
@@ -14,17 +14,10 @@ export type RouteRecordRedirectOption =
1414

1515
/**
1616
* Possible values for a route record **after normalization**
17-
*/
18-
export type RouteRecordNameGeneric = string | symbol | undefined
19-
20-
/**
21-
* Possible values for a user-defined route record's name.
2217
*
23-
* NOTE: since `RouteRecordName` is a type, it evaluates too early and it's always be {@link RouteRecordNameGeneric}. If you need a typed version use {@link RouteMap | `keyof RouteMap`}
18+
* NOTE: since `RouteRecordName` is a type, it evaluates too early and it's always be a generic version. If you need a typed version of all of the names of routes, use {@link RouteMap | `keyof RouteMap`}
2419
*/
25-
export type RouteRecordName = RouteMapGeneric extends RouteMap
26-
? RouteRecordNameGeneric
27-
: keyof RouteMap
20+
export type RouteRecordName = string | symbol | undefined
2821

2922
/**
3023
* @internal

packages/router/src/types/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import type { HistoryState } from '../history/common'
66
import type {
77
NavigationGuardWithThis,
88
RouteLocation,
9-
RouteRecordName,
109
RouteRecordRedirectOption,
1110
_RouteRecordProps,
12-
RouteRecordNameGeneric,
11+
RouteRecordName,
1312
} from '../typed-routes'
1413
import type { _Awaitable } from './utils'
1514

@@ -93,7 +92,7 @@ export interface MatcherLocationAsRelative {
9392
* @internal
9493
*/
9594
export interface LocationAsRelativeRaw {
96-
name?: RouteRecordNameGeneric
95+
name?: RouteRecordName
9796
// to allow checking location.path == null
9897
/**
9998
* Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.

0 commit comments

Comments
 (0)