Skip to content

Commit

Permalink
refactor: proper type for hasSetupState util function
Browse files Browse the repository at this point in the history
  • Loading branch information
cexbrayat committed Nov 15, 2022
1 parent a091420 commit 5523220
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/mount.ts
Expand Up @@ -485,8 +485,8 @@ export function mount(
// otherwise we run into a proxy set error
// due to https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f#diff-ea4d1ddabb7e22e17e80ada458eef70679af4005df2a1a6b73418fec897603ceR404
// introduced in Vue v3.2.45
if (hasSetupState(this as any)) {
;(this as any).$.setupState[k] = v
if (hasSetupState(this)) {
this.$.setupState[k] = v
} else {
;(this as any)[k] = v
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Expand Up @@ -188,7 +188,9 @@ export function getDirectivesFromStubs(
}
export function hasSetupState(
vm: ComponentPublicInstance
): vm is ComponentPublicInstance & { setupState: Record<string, unknown> } {
): vm is ComponentPublicInstance & {
$: { setupState: Record<string, unknown> }
} {
return (
vm &&
(vm.$ as unknown as { devtoolsRawSetupState: any }).devtoolsRawSetupState
Expand Down
2 changes: 1 addition & 1 deletion src/vueWrapper.ts
Expand Up @@ -108,7 +108,7 @@ export class VueWrapper<
// or for components with a setup that returns a render function (as they have an empty proxy)
// in both cases, we return `vm` directly instead
if (hasSetupState(vm)) {
this.componentVM = createVMProxy<T>(vm, (vm.$ as any).setupState)
this.componentVM = createVMProxy<T>(vm, vm.$.setupState)
} else {
this.componentVM = vm
}
Expand Down

0 comments on commit 5523220

Please sign in to comment.