Skip to content

Commit

Permalink
test: add storeToRefs
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 26, 2024
1 parent 5ad1765 commit dee897b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/pinia/test-dts/storeToRefs.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<Ref<number>>(optionsRefs.n)
expectType<Ref<{ n: number; ref: number }>>(optionsRefs.ref)
expectType<Ref<{ n: number; ref: Ref<number> }>>(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<Ref<number>>(setupRefs.n)
expectType<Ref<{ n: number; ref: number }>>(setupRefs.ref)
expectType<Ref<{ n: number; ref: Ref<number> }>>(setupRefs.shallowRef)

0 comments on commit dee897b

Please sign in to comment.