* Extracts the return type for `storeToRefs`.
* Will convert any `getters` into `ComputedRef`.
*/
-export type StoreToRefs<SS extends StoreGeneric> = _ToStateRefs<SS> &
- ToRefs<PiniaCustomStateProperties<StoreState<SS>>> &
- _ToComputedRefs<StoreGetters<SS>>
+export type StoreToRefs<SS extends StoreGeneric> = SS extends unknown
+ ? _ToStateRefs<SS> &
+ ToRefs<PiniaCustomStateProperties<StoreState<SS>>> &
+ _ToComputedRefs<StoreGetters<SS>>
+ : never
/**
* Creates an object of references with all the state, getters, and plugin-added
expectType,
storeToRefs,
} from './'
-import { computed, ref, UnwrapRef, watch } from 'vue'
+import { computed, Ref, ref, UnwrapRef, watch, WritableComputedRef } from 'vue'
const useStore = defineStore({
id: 'name',
refs.bananasAmount.value = 0
// @ts-expect-error: this one is readonly
refs.total.value = 0
+
+const refStore = defineStore('ref-bananas', () => {
+ const bananas = ref(['banana1', 'banana2'])
+ return { bananas }
+})()
+declare const conditionalStore: typeof refStore | typeof writableComputedStore
+expectType<Ref<string[]> | WritableComputedRef<'banana'[]>>(
+ storeToRefs(conditionalStore).bananas
+)