From 731e9dd4bfb407617803109ffbd12c463e7dfe68 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 22 Sep 2022 18:49:03 +0200 Subject: [PATCH] feat(types): RouteLocationRaw #66 --- playground/typed-router.d.ts | 11 +++++++++++ src/codegen/generateDTS.ts | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/playground/typed-router.d.ts b/playground/typed-router.d.ts index df0f1a641..b1eac4714 100644 --- a/playground/typed-router.d.ts +++ b/playground/typed-router.d.ts @@ -10,6 +10,9 @@ import type { RouteLocationResolvedTypedList, RouteLocationNormalizedTypedList, RouteLocationNormalizedLoadedTypedList, + RouteLocationAsString, + RouteLocationAsRelativeTypedList, + RouteLocationAsPathTypedList, // helper types // route definitions @@ -91,6 +94,14 @@ declare module 'vue-router/auto' { */ export type RouteLocation = RouteLocationTypedList[Name] + /** + * Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationRaw = + | RouteLocationAsString + | RouteLocationAsRelativeTypedList[Name] + | RouteLocationAsPathTypedList[Name] + /** * Generate a type safe params for a route location. Requires the name of the route to be passed as a generic. */ diff --git a/src/codegen/generateDTS.ts b/src/codegen/generateDTS.ts index 2c0c3bda3..2f736eee6 100644 --- a/src/codegen/generateDTS.ts +++ b/src/codegen/generateDTS.ts @@ -19,6 +19,9 @@ import type { RouteLocationResolvedTypedList, RouteLocationNormalizedTypedList, RouteLocationNormalizedLoadedTypedList, + RouteLocationAsString, + RouteLocationAsRelativeTypedList, + RouteLocationAsPathTypedList, // helper types // route definitions @@ -71,6 +74,14 @@ declare module '${vueRouterModule}' { */ export type RouteLocation = RouteLocationTypedList[Name] + /** + * Type safe version of \`RouteLocationRaw\` . Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationRaw = + | RouteLocationAsString + | RouteLocationAsRelativeTypedList[Name] + | RouteLocationAsPathTypedList[Name] + /** * Generate a type safe params for a route location. Requires the name of the route to be passed as a generic. */