]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: internal types
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 6 May 2022 10:11:48 +0000 (12:11 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
src/index.ts
src/types/named.ts
src/types/paths.ts

index 74b28e130e387c963fbfba67c0ae7f7e226d0eba..9e978d7fd498baacd02528d7d9659552336e6d84 100644 (file)
@@ -64,7 +64,7 @@ export type {
   _ExtractFirstParamName,
   _RemoveRegexpFromParam,
   _RemoveUntilClosingPar,
-  JoinPath,
+  _JoinPath as JoinPath,
 } from './types/paths'
 export type { RouteNamedMap } from './types/named'
 export type { Config, RouterTyped } from './typedRouter'
index 69a8afc78683d6b0d44b1d52e1f9ab95c94c0d37..4740dc3ab88a57a64ec004f3d2f514398074ac52 100644 (file)
@@ -1,5 +1,5 @@
 import type { RouteParams, RouteParamsRaw, RouteRecordRaw } from '.'
-import type { JoinPath, ParamsFromPath, ParamsRawFromPath } from './paths'
+import type { _JoinPath, ParamsFromPath, ParamsRawFromPath } from './paths'
 
 export type RouteNamedMap<
   Routes extends Readonly<RouteRecordRaw[]>,
@@ -16,10 +16,10 @@ export type RouteNamedMap<
               ? {
                   [N in Name]: {
                     // name: N
-                    params: ParamsFromPath<JoinPath<Prefix, Path>>
+                    params: ParamsFromPath<_JoinPath<Prefix, Path>>
                     // TODO: ParamsRawFromPath
-                    paramsRaw: ParamsRawFromPath<JoinPath<Prefix, Path>>
-                    path: JoinPath<Prefix, Path>
+                    paramsRaw: ParamsRawFromPath<_JoinPath<Prefix, Path>>
+                    path: _JoinPath<Prefix, Path>
                   }
                 }
               : {
@@ -27,7 +27,7 @@ export type RouteNamedMap<
                 }) &
               // Recurse children
               (Children extends Readonly<RouteRecordRaw[]>
-                ? RouteNamedMap<Children, JoinPath<Prefix, Path>>
+                ? RouteNamedMap<Children, _JoinPath<Prefix, Path>>
                 : {
                     // NO_CHILDREN: 1
                   })
@@ -43,7 +43,6 @@ export type RouteNamedMap<
 
 export type RouteNamedMapGeneric = Record<
   string | symbol | number,
-  // TODO: use RouteParams, RouteParamRaw
   {
     params: RouteParams
     paramsRaw: RouteParamsRaw
index 5da7e49d3606d9638bf36e090a305eb467efe12b..8ff156f6988128e03a926a2d17ef90de8314de38 100644 (file)
@@ -86,18 +86,38 @@ export type _ModifierParamValue<
   ? _ParamValueZeroOrOne<isRaw>
   : never
 
+/**
+ * Utility type for raw and non raw params like :id+
+ *
+ * @internal
+ */
 export type _ParamValueOneOrMore<isRaw extends boolean> = true extends isRaw
   ? readonly [string | number, ...(string | number)[]]
   : readonly [string, ...string[]]
 
+/**
+ * Utility type for raw and non raw params like :id*
+ *
+ * @internal
+ */
 export type _ParamValueZeroOrMore<isRaw extends boolean> = true extends isRaw
   ? readonly (string | number)[] | undefined | null
   : readonly string[] | undefined | null
 
+/**
+ * Utility type for raw and non raw params like :id?
+ *
+ * @internal
+ */
 export type _ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw
   ? RouteParamValueRaw
   : string
 
+/**
+ * Utility type for raw and non raw params like :id
+ *
+ * @internal
+ */
 export type _ParamValue<isRaw extends boolean> = true extends isRaw
   ? string | number
   : string
@@ -188,7 +208,7 @@ export type _ExtractFirstParamName<S extends string> =
     : S
 
 /**
- * Join an array of param values
+ * Join an array of param values for repeated params
  *
  * @internal
  */
@@ -215,7 +235,7 @@ export type _ParamToString<V> = V extends null | undefined | readonly string[]
   ? ''
   : V extends string
   ? V
-  : `oops`
+  : never
 
 /**
  * Possible values for a Modifier.
@@ -299,7 +319,12 @@ export type ParamKeysFromPath<P extends string = string> = string extends P
   ? readonly PathParserParamKey[] // Generic version
   : _ExtractPathParamKeys<_RemoveRegexpFromParam<P>>
 
-export type JoinPath<
+/**
+ * Joins a prefix and a path putting a `/` between them when necessary
+ *
+ * @internal
+ */
+export type _JoinPath<
   Prefix extends string,
   Path extends string
 > = Path extends `/${string}`