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)