From: pikax Date: Thu, 8 Apr 2021 17:21:29 +0000 (+0100) Subject: some code changes to make the demo kinda work X-Git-Tag: v4.1.0~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6700327f67b793cf28f77148ee734237d5382d7e;p=thirdparty%2Fvuejs%2Frouter.git some code changes to make the demo kinda work --- diff --git a/src/router.ts b/src/router.ts index f731505a..6e902a40 100644 --- a/src/router.ts +++ b/src/router.ts @@ -254,15 +254,15 @@ export interface Router { * * @param to - Route location to navigate to */ - push(to: RouteLocationRaw): Promise + // push(to: RouteLocationRaw): Promise /** * Programmatically navigate to a new URL by pushing an entry in the history * stack. * * @param to - typed route location */ - push( - to: RouteNamedLocation + push( + to: RouteNamedLocation ): Promise /** diff --git a/src/types/named.ts b/src/types/named.ts index c01521af..663c3b5b 100644 --- a/src/types/named.ts +++ b/src/types/named.ts @@ -33,10 +33,11 @@ export function defineRoutes< } export interface NamedLocationMap {} -export interface RouteNamedLocation - extends RouteLocationOptions { +export interface RouteNamedLocation< + T extends keyof NamedLocationMap = keyof NamedLocationMap +> extends RouteLocationOptions { name: T - params: NamedLocationMap[T] + // params: NamedLocationMap[T] } declare const r: [ diff --git a/test-dts/namedRoutes.test-d.ts b/test-dts/namedRoutes.test-d.ts index 92870cdf..93cc9541 100644 --- a/test-dts/namedRoutes.test-d.ts +++ b/test-dts/namedRoutes.test-d.ts @@ -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 declare module './index' { - interface RouteMeta { - requiresAuth?: boolean - nested: { foo: string } - } + interface NamedLocationMap extends TypedRoutes {} } + +declare const router: Router + +router.push({ + name: '', +})