]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
some code changes to make the demo kinda work
authorpikax <carlos@hypermob.co.uk>
Thu, 8 Apr 2021 17:21:29 +0000 (18:21 +0100)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
src/router.ts
src/types/named.ts
test-dts/namedRoutes.test-d.ts

index f731505ad3e37b121532f27883bd94f7435e9392..6e902a409b8a3c95c09097579ce5d33f13a47124 100644 (file)
@@ -254,15 +254,15 @@ export interface Router {
    *
    * @param to - Route location to navigate to
    */
-  push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>
+  // push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>
   /**
    * Programmatically navigate to a new URL by pushing an entry in the history
    * stack.
    *
    * @param to - typed route location
    */
-  push<T extends keyof NamedLocationMap>(
-    to: RouteNamedLocation<T>
+  push(
+    to: RouteNamedLocation
   ): Promise<NavigationFailure | void | undefined>
 
   /**
index c01521af08acf797e48dcbb13aaeb34a42efceda..663c3b5bc077495617763aa44386d30dc21ecfc3 100644 (file)
@@ -33,10 +33,11 @@ export function defineRoutes<
 }
 export interface NamedLocationMap {}
 
-export interface RouteNamedLocation<T extends keyof NamedLocationMap>
-  extends RouteLocationOptions {
+export interface RouteNamedLocation<
+  T extends keyof NamedLocationMap = keyof NamedLocationMap
+> extends RouteLocationOptions {
   name: T
-  params: NamedLocationMap[T]
+  // params: NamedLocationMap[T]
 }
 
 declare const r: [
index 92870cdf6c557ffada936c3e1d890d4ec0ce1f34..93cc9541f34222e6db1dd6aa10e386baaf989bf7 100644 (file)
@@ -1,9 +1,11 @@
-import { defineRoutes } from './index'
+// NOTE `ExtractNamedRoutes` is not exposed on build, you might need to add export to the type manually
+
+import { ExtractNamedRoutes, Router } from './index'
 import { DefineComponent } from 'vue'
 
 declare const Comp: DefineComponent
 
-const routes = defineRoutes([
+const routes = [
   {
     path: 'my-path',
     name: 'test',
@@ -19,11 +21,16 @@ const routes = defineRoutes([
   //   path: 'my-path',
   //   component: Comp,
   // } as const,
-])
+]
+
+type TypedRoutes = ExtractNamedRoutes<typeof routes>
 
 declare module './index' {
-  interface RouteMeta {
-    requiresAuth?: boolean
-    nested: { foo: string }
-  }
+  interface NamedLocationMap extends TypedRoutes {}
 }
+
+declare const router: Router
+
+router.push({
+  name: '',
+})