1
1
import { expectTypeOf , test } from 'vitest'
2
+ import React from 'react'
2
3
import {
3
4
Link ,
4
5
createLink ,
@@ -9,6 +10,7 @@ import {
9
10
} from '../src'
10
11
import type {
11
12
CreateLinkProps ,
13
+ LinkComponent ,
12
14
ResolveRelativePath ,
13
15
SearchSchemaInput ,
14
16
} from '../src'
@@ -4005,6 +4007,39 @@ test('when passing a component with props to createLink and navigating to the ro
4005
4007
createLink ( ( props ) => expectTypeOf ( props ) . toEqualTypeOf < CreateLinkProps > ( ) )
4006
4008
} )
4007
4009
4010
+ test ( 'that createLink refs forward correctly' , ( ) => {
4011
+ // copied from: https://tanstack.com/router/latest/docs/framework/react/guide/custom-link#basic-example
4012
+ interface BasicLinkProps
4013
+ extends React . AnchorHTMLAttributes < HTMLAnchorElement > { }
4014
+ const BasicLinkComponent = React . forwardRef <
4015
+ HTMLAnchorElement ,
4016
+ BasicLinkProps
4017
+ > ( ( props , ref ) => {
4018
+ return (
4019
+ < a ref = { ref } { ...props } className = { 'block px-3 py-2 text-blue-700' } />
4020
+ )
4021
+ } )
4022
+ const CreatedLinkComponent = createLink ( BasicLinkComponent )
4023
+ const CustomLink : LinkComponent < typeof BasicLinkComponent > = ( props ) => {
4024
+ return < CreatedLinkComponent preload = { 'intent' } { ...props } />
4025
+ }
4026
+
4027
+ expectTypeOf ( BasicLinkComponent )
4028
+ . parameter ( 0 )
4029
+ . toHaveProperty ( 'ref' )
4030
+ . toEqualTypeOf < React . Ref < HTMLAnchorElement > | undefined > ( )
4031
+
4032
+ expectTypeOf ( CreatedLinkComponent )
4033
+ . parameter ( 0 )
4034
+ . toHaveProperty ( 'ref' )
4035
+ . toEqualTypeOf < Parameters < typeof BasicLinkComponent > [ 0 ] [ 'ref' ] > ( )
4036
+
4037
+ expectTypeOf ( CustomLink )
4038
+ . parameter ( 0 )
4039
+ . toHaveProperty ( 'ref' )
4040
+ . toEqualTypeOf < Parameters < typeof BasicLinkComponent > [ 0 ] [ 'ref' ] > ( )
4041
+ } )
4042
+
4008
4043
test ( 'ResolveRelativePath' , ( ) => {
4009
4044
expectTypeOf < ResolveRelativePath < '/' , '/posts' > > ( ) . toEqualTypeOf < '/posts' > ( )
4010
4045
0 commit comments