Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: proper type for hasSetupState util function #1865

Merged
merged 1 commit into from Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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