From 50aa53b524041cc9dac3ece06c228e3f78a6bd22 Mon Sep 17 00:00:00 2001 From: Mikita Kamkou Date: Mon, 1 Apr 2024 13:23:57 +0200 Subject: [PATCH] test: add type tests for stores with actions --- .../pinia/test-dts/customizations.test-d.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/pinia/test-dts/customizations.test-d.ts b/packages/pinia/test-dts/customizations.test-d.ts index 34815e09e9..640ae466ad 100644 --- a/packages/pinia/test-dts/customizations.test-d.ts +++ b/packages/pinia/test-dts/customizations.test-d.ts @@ -215,6 +215,33 @@ expectType<{ ) ) +expectType<{ + n: Ref + customN: Ref & { plusOne: () => void } + double: ComputedRef + myState: Ref + stateOnly: Ref +}>( + storeToRefs( + defineStore('a', () => { + const n = ref(1) + const customN = ref(1) as Ref & { plusOne: () => void } + const double = computed(() => n.value * 2) + + function plusOne() { + customN.value++ + } + + return { + n, + customN, + double, + plusOne, + } + })() + ) +) + expectType<{ n: Ref customN: Ref & { plusOne: () => void } @@ -231,6 +258,36 @@ expectType<{ getters: { double: (state) => state.n * 2, }, + actions: { + plusOne() { + this.n++ + }, + }, + })() + ) +) + +expectType<{ + n: Ref + customN: Ref & { plusOne: () => void } + double: ComputedRef + myState: Ref + stateOnly: Ref +}>( + storeToRefs( + defineStore('a', { + state: () => ({ + n: 1, + customN: ref(1) as Ref & { plusOne: () => void }, + }), + getters: { + double: (state) => state.n * 2, + }, + actions: { + plusOne() { + this.n++ + }, + }, })() ) )