From f692fdfe623389f3d85c90e5a923c5cfb15c0b0b Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 14 Mar 2022 16:09:52 +0100 Subject: [PATCH] feat(warn): avoid vue 2 bug storeToRefs() Related to #852 --- packages/pinia/src/storeToRefs.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/pinia/src/storeToRefs.ts b/packages/pinia/src/storeToRefs.ts index c9dbcd69..d0ba5a4f 100644 --- a/packages/pinia/src/storeToRefs.ts +++ b/packages/pinia/src/storeToRefs.ts @@ -1,4 +1,12 @@ -import { isReactive, isRef, toRaw, toRef, ToRefs } from 'vue-demi' +import { + isReactive, + isRef, + isVue2, + toRaw, + toRef, + ToRefs, + toRefs, +} from 'vue-demi' import { StoreGetters, StoreState } from './store' import type { PiniaCustomStateProperties, StoreGeneric } from './types' @@ -15,6 +23,14 @@ export function storeToRefs( ): ToRefs< StoreState & StoreGetters & PiniaCustomStateProperties> > { + if (__DEV__ && isVue2) { + console.warn( + '[Pinia]: "storeToRefs()" currently only works on Vue 3 until https://github.com/vuejs/pinia/issues/852 is fixed. Please, use "toRefs()" (from vue) instead. This will FAIL in production if not changed.' + ) + // @ts-expect-error: toRefs include methods and others + return toRefs(store) + } + store = toRaw(store) const refs = {} as ToRefs< -- 2.47.2