File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import {
2626 // @ts -ignore
2727 ComponentOptionsMixin ,
2828 MaybeRef ,
29+ AnchorHTMLAttributes ,
2930} from 'vue'
3031import { isSameRouteLocationParams , isSameRouteRecord } from './location'
3132import { routerKey , routeLocationKey } from './injectionSymbols'
@@ -359,18 +360,34 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
359360 */
360361export const RouterLink : _RouterLinkI = RouterLinkImpl as any
361362
363+ /**
364+ * @internal
365+ */
366+ type _RouterLinkPropsTypedBase = AllowedComponentProps &
367+ ComponentCustomProps &
368+ VNodeProps &
369+ RouterLinkProps
370+
371+ /**
372+ * @internal
373+ */
374+ type RouterLinkPropsTyped < Custom extends boolean | undefined > =
375+ Custom extends true
376+ ? _RouterLinkPropsTypedBase & { custom : true }
377+ : _RouterLinkPropsTypedBase & { custom ?: false | undefined } & Omit <
378+ AnchorHTMLAttributes ,
379+ 'href'
380+ >
381+
362382/**
363383 * Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
364384 * automatically for JSX.
365385 *
366386 * @internal
367387 */
368388export interface _RouterLinkI {
369- new ( ) : {
370- $props : AllowedComponentProps &
371- ComponentCustomProps &
372- VNodeProps &
373- RouterLinkProps
389+ new < Custom extends boolean | undefined = boolean | undefined > ( ) : {
390+ $props : RouterLinkPropsTyped < Custom >
374391
375392 $slots : {
376393 default ?: ( {
Original file line number Diff line number Diff line change @@ -27,6 +27,17 @@ describe('Components', () => {
2727 expectTypeOf < JSX . Element > ( < RouterLink class = "link" to = "/foo" /> )
2828 expectTypeOf < JSX . Element > ( < RouterLink to = { { path : '/foo' } } /> )
2929 expectTypeOf < JSX . Element > ( < RouterLink to = { { path : '/foo' } } custom /> )
30+ // event handlers and anchor attrs are allowed when not custom
31+ expectTypeOf < JSX . Element > (
32+ < RouterLink to = "/" onFocus = { ( ) => { } } onClick = { ( ) => { } } />
33+ )
34+ expectTypeOf < JSX . Element > (
35+ < RouterLink to = "/" target = "_blank" rel = "noopener" />
36+ )
37+ // @ts -expect-error: href is intentionally omitted
38+ expectError ( < RouterLink to = "/" href = "/bar" /> )
39+ // @ts -expect-error: onFocus should not be allowed with custom
40+ expectError ( < RouterLink to = "/" custom onFocus = { ( ) => { } } /> )
3041
3142 // RouterView
3243 expectTypeOf < JSX . Element > ( < RouterView class = "view" /> )
You can’t perform that action at this time.
0 commit comments