@@ -44,7 +44,7 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
44
44
export async function mountSuspended < T > (
45
45
component : T ,
46
46
options ?: MountSuspendedOptions < T > ,
47
- ) : Promise < ReturnType < typeof mount < T > > & { setupState : any } > {
47
+ ) : Promise < ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } > {
48
48
const {
49
49
props = { } ,
50
50
attrs = { } ,
@@ -55,46 +55,47 @@ export async function mountSuspended<T>(
55
55
56
56
// @ts -expect-error untyped global __unctx__
57
57
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 > >
59
59
60
60
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 > > ( { } )
63
63
64
- let passedProps : Record < string , any >
64
+ let passedProps : Record < string , unknown >
65
65
const wrappedSetup = async (
66
- props : Record < string , any > ,
66
+ props : Record < string , unknown > ,
67
67
setupContext : SetupContext ,
68
68
) => {
69
69
passedProps = props
70
70
if ( setup ) {
71
- setupState = await setup ( props , setupContext )
71
+ const result = await setup ( props , setupContext )
72
+ setupState = result && typeof result === 'object' ? result : { }
72
73
return setupState
73
74
}
74
75
}
75
76
76
- return new Promise < ReturnType < typeof mount < T > > & { setupState : any } > (
77
+ return new Promise < ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } > (
77
78
( resolve ) => {
78
79
const vm = mount (
79
80
{
80
- setup : ( props : Record < string , any > , ctx : SetupContext ) => {
81
+ setup : ( props : Record < string , unknown > , ctx : SetupContext ) => {
81
82
setupContext = ctx
82
83
return NuxtRoot . setup ( props , {
83
84
...ctx ,
84
85
expose : ( ) => { } ,
85
86
} )
86
87
} ,
87
- render : ( renderContext : any ) =>
88
+ render : ( renderContext : Record < string , unknown > ) =>
88
89
h (
89
90
Suspense ,
90
91
{
91
92
onResolve : ( ) =>
92
93
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 > ) => {
95
96
Object . assign ( setProps , props )
96
97
}
97
- resolve ( vm as any )
98
+ resolve ( vm as ReturnType < typeof mount < T > > & { setupState : Record < string , unknown > } )
98
99
} ) ,
99
100
} ,
100
101
{
@@ -110,7 +111,7 @@ export async function mountSuspended<T>(
110
111
name : 'MountSuspendedComponent' ,
111
112
...component ,
112
113
render : render
113
- ? function ( this : any , _ctx : any , ...args : any [ ] ) {
114
+ ? function ( this : unknown , _ctx : Record < string , unknown > , ...args : unknown [ ] ) {
114
115
for ( const key in setupState || { } ) {
115
116
renderContext [ key ] = isReadonly ( setupState [ key ] ) ? unref ( setupState [ key ] ) : setupState [ key ]
116
117
}
@@ -123,7 +124,7 @@ export async function mountSuspended<T>(
123
124
return render . call ( this , renderContext , ...args )
124
125
}
125
126
: undefined ,
126
- setup : setup ? ( props : Record < string , any > ) => wrappedSetup ( props , setupContext ) : undefined ,
127
+ setup : setup ? ( props : Record < string , unknown > ) => wrappedSetup ( props , setupContext ) : undefined ,
127
128
}
128
129
129
130
return ( ) => h ( clonedComponent , { ...defu ( setProps , props ) as typeof props , ...attrs } , slots )
@@ -144,7 +145,7 @@ export async function mountSuspended<T>(
144
145
stubs : {
145
146
Suspense : false ,
146
147
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 ,
148
149
} ,
149
150
components : { RouterLink } ,
150
151
} ,
@@ -154,3 +155,8 @@ export async function mountSuspended<T>(
154
155
} ,
155
156
)
156
157
}
158
+
159
+ interface AugmentedVueInstance {
160
+ setupState ?: Record < string , unknown >
161
+ __setProps ?: ( props : Record < string , unknown > ) => void
162
+ }
0 commit comments