Skip to content

Commit f692fdf

Browse files
committed
feat(warn): avoid vue 2 bug storeToRefs()
Related to #852
1 parent a5515b0 commit f692fdf

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/pinia/src/storeToRefs.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { isReactive, isRef, toRaw, toRef, ToRefs } from 'vue-demi'
1+
import {
2+
isReactive,
3+
isRef,
4+
isVue2,
5+
toRaw,
6+
toRef,
7+
ToRefs,
8+
toRefs,
9+
} from 'vue-demi'
210
import { StoreGetters, StoreState } from './store'
311
import type { PiniaCustomStateProperties, StoreGeneric } from './types'
412

@@ -15,6 +23,14 @@ export function storeToRefs<SS extends StoreGeneric>(
1523
): ToRefs<
1624
StoreState<SS> & StoreGetters<SS> & PiniaCustomStateProperties<StoreState<SS>>
1725
> {
26+
if (__DEV__ && isVue2) {
27+
console.warn(
28+
'[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.'
29+
)
30+
// @ts-expect-error: toRefs include methods and others
31+
return toRefs(store)
32+
}
33+
1834
store = toRaw(store)
1935

2036
const refs = {} as ToRefs<

0 commit comments

Comments
 (0)