]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: remove RouteRecordNameGeneric
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 13 Jun 2024 08:43:50 +0000 (10:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 13 Jun 2024 08:43:50 +0000 (10:43 +0200)
packages/router/src/index.ts
packages/router/src/router.ts
packages/router/src/typed-routes/route-location.ts
packages/router/src/typed-routes/route-records.ts
packages/router/src/types/index.ts

index 277acd3916b8c2f7f4ce16d04a92785ce626c690..c40e2d2cda6e5e0f85cd0cc5b54343cce0f6b36a 100644 (file)
@@ -115,7 +115,6 @@ export type {
   // route records
   RouteRecordInfo,
   RouteRecordName,
-  RouteRecordNameGeneric,
   _RouteRecordProps,
   RouteRecordRedirectOption,
 
index b54e0ceced6d25c65998e5ac4784eec419c6c864..db12647fee01492ec090d17e72e4a895e01869d1 100644 (file)
@@ -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<RouteRecordName>,
     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<RouteRecordName>): void
   /**
    * Checks if a route with a given name exists
    *
index cdcd44a233ee65e137f42d346ea616bebfe736e6..e68f3e2b68cdb0b10e008de2457a1fe2c4516c1c 100644 (file)
@@ -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}
index 0118e58c932ecd96543df4c672497ba478589d5f..14509864ba8b6249e4ab0ade16b650a6e1e51251 100644 (file)
@@ -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
index 5281a2f4988c8d31ce2b6bf1c04387d109d81127..b9383b1631a591070633da18ff588823a7dd3426 100644 (file)
@@ -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.