@@ -44,7 +44,7 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
4444export async function mountSuspended < T > (
4545 component : T ,
4646 options ?: MountSuspendedOptions < T > ,
47- ) : Promise < ReturnType < typeof mount < T > > & { setupState : any } > {
47+ ) : Promise < ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } > {
4848 const {
4949 props = { } ,
5050 attrs = { } ,
@@ -55,46 +55,47 @@ export async function mountSuspended<T>(
5555
5656 // @ts -expect-error untyped global __unctx__
5757 const vueApp = globalThis . __unctx__ . get ( 'nuxt-app' ) . tryUse ( ) . vueApp
58- const { render, setup } = component as DefineComponent < any , any >
58+ const { render, setup } = component as DefineComponent < Record < string , unknown > , Record < string , unknown > >
5959
6060 let setupContext : SetupContext
61- let setupState : any
62- const setProps = reactive < Record < string , any > > ( { } )
61+ let setupState : Record < string , unknown >
62+ const setProps = reactive < Record < string , unknown > > ( { } )
6363
64- let passedProps : Record < string , any >
64+ let passedProps : Record < string , unknown >
6565 const wrappedSetup = async (
66- props : Record < string , any > ,
66+ props : Record < string , unknown > ,
6767 setupContext : SetupContext ,
6868 ) => {
6969 passedProps = props
7070 if ( setup ) {
71- setupState = await setup ( props , setupContext )
71+ const result = await setup ( props , setupContext )
72+ setupState = result && typeof result === 'object' ? result : { }
7273 return setupState
7374 }
7475 }
7576
76- return new Promise < ReturnType < typeof mount < T > > & { setupState : any } > (
77+ return new Promise < ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } > (
7778 ( resolve ) => {
7879 const vm = mount (
7980 {
80- setup : ( props : Record < string , any > , ctx : SetupContext ) => {
81+ setup : ( props : Record < string , unknown > , ctx : SetupContext ) => {
8182 setupContext = ctx
8283 return NuxtRoot . setup ( props , {
8384 ...ctx ,
8485 expose : ( ) => { } ,
8586 } )
8687 } ,
87- render : ( renderContext : any ) =>
88+ render : ( renderContext : Record < string , unknown > ) =>
8889 h (
8990 Suspense ,
9091 {
9192 onResolve : ( ) =>
9293 nextTick ( ) . then ( ( ) => {
93- ( vm as any ) . setupState = setupState ;
94- ( vm as any ) . __setProps = ( props : Record < string , any > ) => {
94+ ( vm as unknown as AugmentedVueInstance ) . setupState = setupState ;
95+ ( vm as unknown as AugmentedVueInstance ) . __setProps = ( props : Record < string , unknown > ) => {
9596 Object . assign ( setProps , props )
9697 }
97- resolve ( vm as any )
98+ resolve ( vm as ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } )
9899 } ) ,
99100 } ,
100101 {
@@ -110,7 +111,7 @@ export async function mountSuspended<T>(
110111 name : 'MountSuspendedComponent' ,
111112 ...component ,
112113 render : render
113- ? function ( this : any , _ctx : any , ...args : any [ ] ) {
114+ ? function ( this : unknown , _ctx : Record < string , unknown > , ...args : unknown [ ] ) {
114115 for ( const key in setupState || { } ) {
115116 renderContext [ key ] = isReadonly ( setupState [ key ] ) ? unref ( setupState [ key ] ) : setupState [ key ]
116117 }
@@ -123,7 +124,7 @@ export async function mountSuspended<T>(
123124 return render . call ( this , renderContext , ...args )
124125 }
125126 : undefined ,
126- setup : setup ? ( props : Record < string , any > ) => wrappedSetup ( props , setupContext ) : undefined ,
127+ setup : setup ? ( props : Record < string , unknown > ) => wrappedSetup ( props , setupContext ) : undefined ,
127128 }
128129
129130 return ( ) => h ( clonedComponent , { ...defu ( setProps , props ) as typeof props , ...attrs } , slots )
@@ -144,7 +145,7 @@ export async function mountSuspended<T>(
144145 stubs : {
145146 Suspense : false ,
146147 MountSuspendedHelper : false ,
147- [ typeof ( component as any ) . name === 'string' ? ( component as any ) . name : 'MountSuspendedComponent' ] : false ,
148+ [ component && typeof component === 'object' && 'name' in component && typeof component . name === 'string' ? component . name : 'MountSuspendedComponent' ] : false ,
148149 } ,
149150 components : { RouterLink } ,
150151 } ,
@@ -154,3 +155,8 @@ export async function mountSuspended<T>(
154155 } ,
155156 )
156157}
158+
159+ interface AugmentedVueInstance {
160+ setupState ?: Record < string , unknown >
161+ __setProps ?: ( props : Record < string , unknown > ) => void
162+ }
0 commit comments