From: Eduardo San Martin Morote Date: Fri, 6 May 2022 10:11:48 +0000 (+0200) Subject: refactor: internal types X-Git-Tag: v4.1.0~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4558737bf5355c431d38fbc67736e1db28617ec4;p=thirdparty%2Fvuejs%2Frouter.git refactor: internal types --- diff --git a/src/index.ts b/src/index.ts index 74b28e13..9e978d7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' diff --git a/src/types/named.ts b/src/types/named.ts index 69a8afc7..4740dc3a 100644 --- a/src/types/named.ts +++ b/src/types/named.ts @@ -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, @@ -16,10 +16,10 @@ export type RouteNamedMap< ? { [N in Name]: { // name: N - params: ParamsFromPath> + params: ParamsFromPath<_JoinPath> // TODO: ParamsRawFromPath - paramsRaw: ParamsRawFromPath> - path: JoinPath + paramsRaw: ParamsRawFromPath<_JoinPath> + path: _JoinPath } } : { @@ -27,7 +27,7 @@ export type RouteNamedMap< }) & // Recurse children (Children extends Readonly - ? RouteNamedMap> + ? RouteNamedMap> : { // 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 diff --git a/src/types/paths.ts b/src/types/paths.ts index 5da7e49d..8ff156f6 100644 --- a/src/types/paths.ts +++ b/src/types/paths.ts @@ -86,18 +86,38 @@ export type _ModifierParamValue< ? _ParamValueZeroOrOne : never +/** + * Utility type for raw and non raw params like :id+ + * + * @internal + */ export type _ParamValueOneOrMore = 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 = 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 = true extends isRaw ? RouteParamValueRaw : string +/** + * Utility type for raw and non raw params like :id + * + * @internal + */ export type _ParamValue = true extends isRaw ? string | number : string @@ -188,7 +208,7 @@ export type _ExtractFirstParamName = : 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 extends null | undefined | readonly string[] ? '' : V extends string ? V - : `oops` + : never /** * Possible values for a Modifier. @@ -299,7 +319,12 @@ export type ParamKeysFromPath

= string extends P ? readonly PathParserParamKey[] // Generic version : _ExtractPathParamKeys<_RemoveRegexpFromParam

> -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}`