From: Eduardo San Martin Morote Date: Tue, 3 May 2022 14:38:31 +0000 (+0200) Subject: refactor(types): add path generics X-Git-Tag: v4.1.0~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55c20f0ef0cef5ce5b6700299374b360f86996bd;p=thirdparty%2Fvuejs%2Frouter.git refactor(types): add path generics --- diff --git a/src/types/index.ts b/src/types/index.ts index 5124a45f..3cfc9698 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -199,14 +199,15 @@ export type _RouteRecordProps = * Common properties among all kind of {@link RouteRecordRaw} * @internal */ -export interface _RouteRecordBase extends PathParserOptions { +export interface _RouteRecordBase + extends PathParserOptions { /** * Path of the record. Should start with `/` unless the record is the child of * another record. * * @example `/users/:id` matches `/users/1` as well as `/users/posva`. */ - path: string + path: Path /** * Where to redirect if the route is directly matched. The redirection happens @@ -269,7 +270,8 @@ export type RouteRecordRedirectOption = /** * Route Record defining one single component with the `component` option. */ -export interface RouteRecordSingleView extends _RouteRecordBase { +export interface RouteRecordSingleView + extends _RouteRecordBase { /** * Component to display when the URL matches this route. */ @@ -284,7 +286,8 @@ export interface RouteRecordSingleView extends _RouteRecordBase { /** * Route Record defining one single component with a nested view. */ -export interface RouteRecordSingleViewWithChildren extends _RouteRecordBase { +export interface RouteRecordSingleViewWithChildren + extends _RouteRecordBase { /** * Component to display when the URL matches this route. */ @@ -305,7 +308,8 @@ export interface RouteRecordSingleViewWithChildren extends _RouteRecordBase { /** * Route Record defining multiple named components with the `components` option. */ -export interface RouteRecordMultipleViews extends _RouteRecordBase { +export interface RouteRecordMultipleViews + extends _RouteRecordBase { /** * Components to display when the URL matches this route. Allow using named views. */ @@ -323,7 +327,9 @@ export interface RouteRecordMultipleViews extends _RouteRecordBase { /** * Route Record defining multiple named components with the `components` option and children. */ -export interface RouteRecordMultipleViewsWithChildren extends _RouteRecordBase { +export interface RouteRecordMultipleViewsWithChildren< + Path extends string = string +> extends _RouteRecordBase { /** * Components to display when the URL matches this route. Allow using named views. */ @@ -344,18 +350,19 @@ export interface RouteRecordMultipleViewsWithChildren extends _RouteRecordBase { * Route Record that defines a redirect. Cannot have `component` or `components` * as it is never rendered. */ -export interface RouteRecordRedirect extends _RouteRecordBase { +export interface RouteRecordRedirect + extends _RouteRecordBase { redirect: RouteRecordRedirectOption component?: never components?: never } -export type RouteRecordRaw = - | RouteRecordSingleView - | RouteRecordSingleViewWithChildren - | RouteRecordMultipleViews - | RouteRecordMultipleViewsWithChildren - | RouteRecordRedirect +export type RouteRecordRaw = + | RouteRecordSingleView + | RouteRecordSingleViewWithChildren + | RouteRecordMultipleViews + | RouteRecordMultipleViewsWithChildren + | RouteRecordRedirect /** * Initial route location where the router is. Can be used in navigation guards