Skip to content

Commit

Permalink
feat(warn): avoid vue 2 bug storeToRefs()
Browse files Browse the repository at this point in the history
Related to #852
  • Loading branch information
posva committed Mar 14, 2022
1 parent a5515b0 commit f692fdf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion 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'

Expand All @@ -15,6 +23,14 @@ export function storeToRefs<SS extends StoreGeneric>(
): ToRefs<
StoreState<SS> & StoreGetters<SS> & PiniaCustomStateProperties<StoreState<SS>>
> {
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<
Expand Down

0 comments on commit f692fdf

Please sign in to comment.