Skip to content

Commit

Permalink
refactor: remove RouteRecordNameGeneric
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 13, 2024
1 parent 958a1ad commit 3675b05
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export type {
// route records
RouteRecordInfo,
RouteRecordName,
RouteRecordNameGeneric,
_RouteRecordProps,
RouteRecordRedirectOption,

Expand Down
5 changes: 3 additions & 2 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import type {
RouteLocation,
RouteLocationRaw,
RouteRecordName,
RouteParams,
RouteLocationNormalized,
RouteLocationNormalizedLoaded,
Expand All @@ -19,6 +18,7 @@ import type {
RouteLocationAsRelative,
RouteLocationAsPath,
RouteLocationAsString,
RouteRecordName,
} from './typed-routes'
import { RouterHistory, HistoryState, NavigationType } from './history/common'
import {
Expand Down Expand Up @@ -212,6 +212,7 @@ export interface Router {
* @param route - Route Record to add
*/
addRoute(
// NOTE: RouteRecordName could be `keyof RouteMap` but the point of dynamic routes is not knowing the routes at build
parentName: NonNullable<RouteRecordName>,
route: RouteRecordRaw
): () => void
Expand All @@ -226,7 +227,7 @@ export interface Router {
*
* @param name - Name of the route to remove
*/
removeRoute(name: RouteRecordName): void
removeRoute(name: NonNullable<RouteRecordName>): void
/**
* Checks if a route with a given name exists
*
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/typed-routes/route-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { _LiteralUnion } from '../types/utils'
import type { RouteMap, RouteMapGeneric } from './route-map'
import type { Router } from '../router'
import type { RouteRecord, RouteRecordNormalized } from '../matcher/types'
import type { RouteRecordName, RouteRecordNameGeneric } from './route-records'
import type { RouteRecordName } from './route-records'

/**
* Generic version of {@link RouteLocation}. It is used when no {@link RouteMap} is provided.
Expand Down Expand Up @@ -49,7 +49,7 @@ export type RouteLocationTypedList<
* Generic version of {@link RouteLocationNormalized} that is used when no {@link RouteMap} is provided.
*/
export interface RouteLocationNormalizedGeneric extends _RouteLocationBase {
name: RouteRecordNameGeneric
name: RouteRecordName
params: RouteParamsGeneric
/**
* Array of {@link RouteRecordNormalized}
Expand Down
13 changes: 3 additions & 10 deletions packages/router/src/typed-routes/route-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
RouteLocationNormalized,
RouteLocationRaw,
} from './route-location'
import type { RouteMap, RouteMapGeneric } from './route-map'
import type { RouteMap } from './route-map'

/**
* @internal
Expand All @@ -14,17 +14,10 @@ export type RouteRecordRedirectOption =

/**
* Possible values for a route record **after normalization**
*/
export type RouteRecordNameGeneric = string | symbol | undefined

/**
* Possible values for a user-defined route record's name.
*
* 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`}
* 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`}
*/
export type RouteRecordName = RouteMapGeneric extends RouteMap
? RouteRecordNameGeneric
: keyof RouteMap
export type RouteRecordName = string | symbol | undefined

/**
* @internal
Expand Down
5 changes: 2 additions & 3 deletions packages/router/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import type { HistoryState } from '../history/common'
import type {
NavigationGuardWithThis,
RouteLocation,
RouteRecordName,
RouteRecordRedirectOption,
_RouteRecordProps,
RouteRecordNameGeneric,
RouteRecordName,
} from '../typed-routes'
import type { _Awaitable } from './utils'

Expand Down Expand Up @@ -93,7 +92,7 @@ export interface MatcherLocationAsRelative {
* @internal
*/
export interface LocationAsRelativeRaw {
name?: RouteRecordNameGeneric
name?: RouteRecordName
// to allow checking location.path == null
/**
* Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
Expand Down

0 comments on commit 3675b05

Please sign in to comment.