From: pikax Date: Fri, 9 Apr 2021 12:17:23 +0000 (+0100) Subject: improvements X-Git-Tag: v4.1.0~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1ef9732780fa4b12df1dc5226fb69ea82cf67a5;p=thirdparty%2Fvuejs%2Frouter.git improvements --- diff --git a/src/types/named.ts b/src/types/named.ts index e3d83264..c478605d 100644 --- a/src/types/named.ts +++ b/src/types/named.ts @@ -7,35 +7,6 @@ export type ExtractNamedRoutes = [T] extends [ReadonlyArray] ? ExtractNamedRoutes : {}) -// declare const test: ExtractNamedRoutes< -// [ -// { -// path: 'my-path' -// name: 'test' -// children: [] -// }, -// { -// path: 'my-path' -// name: 'my-other-path' -// // children: [] -// }, -// { -// path: 'random' -// name: 'tt' -// children: [ -// { -// path: 'random-child' -// name: 'random-child' -// } -// ] -// } -// ] -// > -// test -// test['my-other-path'] -// test.test, test.tt -// test['random-child'] - export function defineRoutes< T extends Array> >(routes: T): ExtractNamedRoutes { diff --git a/test-dts/namedRoutes.test-d.ts b/test-dts/namedRoutes.test-d.ts index 6ad366d6..d7fbf19d 100644 --- a/test-dts/namedRoutes.test-d.ts +++ b/test-dts/namedRoutes.test-d.ts @@ -8,11 +8,15 @@ const routes = [ path: 'my-path', name: 'test', component: Comp, + // children must be declared :( + children: [], }, { path: 'my-path', name: 'my-other-path', component: Comp, + // children must be declared :( + children: [], }, { path: 'random', @@ -22,39 +26,35 @@ const routes = [ path: 'random-child', name: 'random-child', component: Comp, + children: [], }, ], }, -] - -type TypedRoutes = ExtractNamedRoutes< [ - { - path: 'my-path', - name: 'test', - // component: , - }, - { - path: 'my-path', - name: 'my-other-path', - // component: Comp, - }, { - path: 'random', - name: 'tt', + name: '1', children: [ { - path: 'random-child', - name: 'random-child', - component: {}, + name: '2', + children: [{ name: '3' }], }, ], }, -]> +] as const + +declare const typed: ExtractNamedRoutes + +typed['my-other-path'] +typed['random-child'] +typed.test +typed.tt +typed[1] +typed[2] +typed[3] declare module './index' { - interface NamedLocationMap { + interface NamedLocationMap { 'my-other-path': { - sss: number + sss: number } } } @@ -66,8 +66,8 @@ router.push({ params: { sss: 1, // @ts-expect-error does not exist - xxxx: '22' - } + xxxx: '22', + }, }) router.push({