From 4a9b1075050ce84bbf04dfc2cb74a1d5af2d7247 Mon Sep 17 00:00:00 2001 From: ced Date: Tue, 15 Nov 2022 11:38:11 +0100 Subject: [PATCH] refactor: proper type for hasSetupState util function --- src/mount.ts | 4 ++-- src/utils.ts | 4 +++- src/vueWrapper.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index a991814d6..afeca3239 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -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 } diff --git a/src/utils.ts b/src/utils.ts index e2780518f..a6a99185b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -188,7 +188,9 @@ export function getDirectivesFromStubs( } export function hasSetupState( vm: ComponentPublicInstance -): vm is ComponentPublicInstance & { setupState: Record } { +): vm is ComponentPublicInstance & { + $: { setupState: Record } +} { return ( vm && (vm.$ as unknown as { devtoolsRawSetupState: any }).devtoolsRawSetupState diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index 356ae09d9..1d5fb40a0 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -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(vm, (vm.$ as any).setupState) + this.componentVM = createVMProxy(vm, vm.$.setupState) } else { this.componentVM = vm }