File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ import { RouteRecord } from './matcher/types'
41
41
import { NavigationFailure } from './errors'
42
42
import { isArray , isBrowser , noop } from './utils'
43
43
import type { Router } from './router'
44
- import { RouteNamedMap , RouteStaticPathMap } from './types/named'
44
+ import type { RouteNamedMap , RouteStaticPathMap } from './types/named'
45
+ import type { RouterTyped } from './typedRouter'
45
46
46
47
export interface RouterLinkOptions <
47
48
Routes extends RouteLocationRaw = RouteLocationRaw
@@ -262,7 +263,11 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
262
263
*/
263
264
export const RouterLink = RouterLinkImpl as unknown as RouterLinkTyped
264
265
265
- export interface RouterLinkTyped < R extends Router = Router > {
266
+ /**
267
+ * Typed version of the `RouterLink` component. Its generic defaults to the typed router so it can be inferred
268
+ * automatically for JSX.
269
+ */
270
+ export interface RouterLinkTyped < R extends Router = RouterTyped > {
266
271
new ( ) : {
267
272
$props : AllowedComponentProps &
268
273
ComponentCustomProps &
Original file line number Diff line number Diff line change 1
- import {
1
+ import type {
2
2
NavigationGuardWithThis ,
3
3
NavigationGuard ,
4
4
RouteLocationNormalizedLoaded ,
5
5
} from './types'
6
6
import { RouterView } from './RouterView'
7
- import { RouterLink } from './RouterLink'
8
- import { RouterTyped } from './typedRouter'
7
+ import type { RouterLinkTyped } from './RouterLink'
8
+ import type { RouterTyped } from './typedRouter'
9
9
10
10
declare module '@vue/runtime-core' {
11
11
export interface ComponentCustomOptions {
@@ -60,6 +60,6 @@ declare module '@vue/runtime-core' {
60
60
61
61
export interface GlobalComponents {
62
62
RouterView : typeof RouterView
63
- RouterLink : typeof RouterLink
63
+ RouterLink : RouterLinkTyped < RouterTyped >
64
64
}
65
65
}
Original file line number Diff line number Diff line change @@ -13,17 +13,19 @@ let router = createRouter({
13
13
} )
14
14
15
15
// RouterLink
16
- // @ts -expect-error
16
+ // @ts -expect-error missing to
17
17
expectError ( < RouterLink /> )
18
- // @ts -expect-error
18
+ // @ts -expect-error: invalid prop
19
19
expectError ( < RouterLink to = "/" custom = "text" /> )
20
- // @ts -expect-error
20
+ // @ts -expect-error: invalid prop
21
21
expectError ( < RouterLink to = "/" replace = "text" /> )
22
22
expectType < JSX . Element > ( < RouterLink to = "/foo" replace /> )
23
23
expectType < JSX . Element > ( < RouterLink to = "/foo" /> )
24
24
expectType < JSX . Element > ( < RouterLink class = "link" to = "/foo" /> )
25
25
expectType < JSX . Element > ( < RouterLink to = { { path : '/foo' } } /> )
26
26
expectType < JSX . Element > ( < RouterLink to = { { path : '/foo' } } custom /> )
27
+ // @ts -expect-error: non existing name
28
+ expectType < JSX . Element > ( < RouterLink to = { { name : 'nope' } } custom /> )
27
29
28
30
// RouterView
29
31
expectType < JSX . Element > ( < RouterView class = "view" /> )
You can’t perform that action at this time.
0 commit comments