Skip to content

Commit 591bbea

Browse files
authored
feat(types): export the LocationUrl type from virtual:uni-pages (#233)
1 parent f42e1b4 commit 591bbea

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

packages/core/src/declaration.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ export function getDeclaration(ctx: PageContext) {
1818
// @ts-nocheck
1919
// Generated by vite-plugin-uni-pages
2020
21+
type _LocationUrl =
22+
${allPagesPath.join(' |\n ')};
23+
2124
interface NavigateToOptions {
22-
url: ${allPagesPath.join(' |\n ')};
25+
url: _LocationUrl;
2326
}
2427
interface RedirectToOptions extends NavigateToOptions {}
2528
@@ -35,6 +38,10 @@ declare interface Uni {
3538
switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void;
3639
reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void;
3740
}
41+
42+
declare module "virtual:uni-pages" {
43+
export type LocationUrl = _LocationUrl;
44+
}
3845
`
3946
return code
4047
}

packages/playground/src/uni-pages.d.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@
33
// @ts-nocheck
44
// Generated by vite-plugin-uni-pages
55

6+
type _LocationUrl =
7+
"/pages/index" |
8+
"/pages/A-top" |
9+
"/pages/i18n" |
10+
"/pages/test-json" |
11+
"/pages/test-jsonc-with-comment" |
12+
"/pages/test-yaml" |
13+
"/pages/test" |
14+
"/pages/blog/index" |
15+
"/pages/blog/post" |
16+
"/pages/define-page/async-function" |
17+
"/pages/define-page/conditional-compilation" |
18+
"/pages/define-page/function" |
19+
"/pages/define-page/nested-function" |
20+
"/pages/define-page/object" |
21+
"/pages/define-page/option-api" |
22+
"/pages/define-page/remove-console" |
23+
"/pages/define-page/yaml" |
24+
"/pages-sub/index" |
25+
"/pages-sub/about/index" |
26+
"/pages-sub/about/your";
27+
628
interface NavigateToOptions {
7-
url: "/pages/index" |
8-
"/pages/A-top" |
9-
"/pages/i18n" |
10-
"/pages/test-json" |
11-
"/pages/test-jsonc-with-comment" |
12-
"/pages/test-yaml" |
13-
"/pages/test" |
14-
"/pages/blog/index" |
15-
"/pages/blog/post" |
16-
"/pages/define-page/async-function" |
17-
"/pages/define-page/conditional-compilation" |
18-
"/pages/define-page/function" |
19-
"/pages/define-page/nested-function" |
20-
"/pages/define-page/object" |
21-
"/pages/define-page/option-api" |
22-
"/pages/define-page/remove-console" |
23-
"/pages/define-page/yaml" |
24-
"/pages-sub/index" |
25-
"/pages-sub/about/index" |
26-
"/pages-sub/about/your";
29+
url: _LocationUrl;
2730
}
2831
interface RedirectToOptions extends NavigateToOptions {}
2932

@@ -39,3 +42,7 @@ declare interface Uni {
3942
switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void;
4043
reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void;
4144
}
45+
46+
declare module "virtual:uni-pages" {
47+
export type LocationUrl = _LocationUrl;
48+
}

0 commit comments

Comments
 (0)