Skip to content

Commit

Permalink
test: add type tests for stores with actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nkeyy0 committed Apr 1, 2024
1 parent 1d54589 commit 50aa53b
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/pinia/test-dts/customizations.test-d.ts
Original file line number Diff line number Diff line change
@@ -215,6 +215,33 @@ expectType<{
)
)

expectType<{
n: Ref<number>
customN: Ref<number> & { plusOne: () => void }
double: ComputedRef<number>
myState: Ref<number>
stateOnly: Ref<number>
}>(
storeToRefs(
defineStore('a', () => {
const n = ref(1)
const customN = ref(1) as Ref<number> & { plusOne: () => void }
const double = computed(() => n.value * 2)

function plusOne() {
customN.value++
}

return {
n,
customN,
double,
plusOne,
}
})()
)
)

expectType<{
n: Ref<number>
customN: Ref<number> & { plusOne: () => void }
@@ -231,6 +258,36 @@ expectType<{
getters: {
double: (state) => state.n * 2,
},
actions: {
plusOne() {
this.n++
},
},
})()
)
)

expectType<{
n: Ref<number>
customN: Ref<number> & { plusOne: () => void }
double: ComputedRef<number>
myState: Ref<number>
stateOnly: Ref<number>
}>(
storeToRefs(
defineStore('a', {
state: () => ({
n: 1,
customN: ref(1) as Ref<number> & { plusOne: () => void },
}),
getters: {
double: (state) => state.n * 2,
},
actions: {
plusOne() {
this.n++
},
},
})()
)
)

0 comments on commit 50aa53b

Please sign in to comment.