diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index 277acd391..c40e2d2cd 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -115,7 +115,6 @@ export type { // route records RouteRecordInfo, RouteRecordName, - RouteRecordNameGeneric, _RouteRecordProps, RouteRecordRedirectOption, diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index b54e0cece..db12647fe 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -9,7 +9,6 @@ import { import type { RouteLocation, RouteLocationRaw, - RouteRecordName, RouteParams, RouteLocationNormalized, RouteLocationNormalizedLoaded, @@ -19,6 +18,7 @@ import type { RouteLocationAsRelative, RouteLocationAsPath, RouteLocationAsString, + RouteRecordName, } from './typed-routes' import { RouterHistory, HistoryState, NavigationType } from './history/common' import { @@ -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, route: RouteRecordRaw ): () => void @@ -226,7 +227,7 @@ export interface Router { * * @param name - Name of the route to remove */ - removeRoute(name: RouteRecordName): void + removeRoute(name: NonNullable): void /** * Checks if a route with a given name exists * diff --git a/packages/router/src/typed-routes/route-location.ts b/packages/router/src/typed-routes/route-location.ts index cdcd44a23..e68f3e2b6 100644 --- a/packages/router/src/typed-routes/route-location.ts +++ b/packages/router/src/typed-routes/route-location.ts @@ -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. @@ -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} diff --git a/packages/router/src/typed-routes/route-records.ts b/packages/router/src/typed-routes/route-records.ts index 0118e58c9..14509864b 100644 --- a/packages/router/src/typed-routes/route-records.ts +++ b/packages/router/src/typed-routes/route-records.ts @@ -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 @@ -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 diff --git a/packages/router/src/types/index.ts b/packages/router/src/types/index.ts index 5281a2f49..b9383b163 100644 --- a/packages/router/src/types/index.ts +++ b/packages/router/src/types/index.ts @@ -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' @@ -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.