From: Eduardo San Martin Morote Date: Mon, 14 Mar 2022 15:09:52 +0000 (+0100) Subject: feat(warn): avoid vue 2 bug storeToRefs() X-Git-Tag: @pinia/testing@0.0.10~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f692fdfe623389f3d85c90e5a923c5cfb15c0b0b;p=thirdparty%2Fvuejs%2Fpinia.git feat(warn): avoid vue 2 bug storeToRefs() Related to #852 --- 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<