From dee897b16c70d5fa6c4835799defe2eba5c67544 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 26 Sep 2024 11:44:49 +0200 Subject: [PATCH] test: add storeToRefs --- packages/pinia/test-dts/storeToRefs.test-d.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/pinia/test-dts/storeToRefs.test-d.ts diff --git a/packages/pinia/test-dts/storeToRefs.test-d.ts b/packages/pinia/test-dts/storeToRefs.test-d.ts new file mode 100644 index 0000000000..6fc198ea17 --- /dev/null +++ b/packages/pinia/test-dts/storeToRefs.test-d.ts @@ -0,0 +1,50 @@ +import { + expectType, + createPinia, + defineStore, + mapStores, + storeToRefs, +} from './' +import { App, computed, ComputedRef, ref, Ref, shallowRef } from 'vue' + +const useOptionsStore = defineStore('main', { + state: () => ({ + n: 0, + ref: ref({ + n: 0, + ref: ref(0), + }), + shallowRef: shallowRef({ + n: 0, + ref: ref(0), + }), + }), +}) + +const optionsStore = useOptionsStore() +const optionsRefs = storeToRefs(optionsStore) + +expectType>(optionsRefs.n) +expectType>(optionsRefs.ref) +expectType }>>(optionsRefs.shallowRef) + +const useSetupStore = defineStore('main', () => { + return { + n: ref(0), + ref: ref({ + n: 0, + ref: ref(0), + }), + shallowRef: shallowRef({ + n: 0, + ref: ref(0), + }), + } +}) + +const setupStore = useSetupStore() +const setupRefs = storeToRefs(setupStore) + +expectType>(setupRefs.n) +expectType>(setupRefs.ref) +expectType }>>(setupRefs.shallowRef)