From f550c6080514a851f77a652becbf5b90818479d1 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 4 Apr 2024 10:39:01 +0200 Subject: [PATCH] refactor: Revert "fix(types): fix storeToRefs state return type (#2574) (#2604)" This reverts commit c8f727a0a2187c591134bd467efe426fb747ea40. --- packages/pinia/src/storeToRefs.ts | 34 +-------- .../pinia/test-dts/customizations.test-d.ts | 73 ------------------- 2 files changed, 4 insertions(+), 103 deletions(-) diff --git a/packages/pinia/src/storeToRefs.ts b/packages/pinia/src/storeToRefs.ts index a6b91217..76e91c33 100644 --- a/packages/pinia/src/storeToRefs.ts +++ b/packages/pinia/src/storeToRefs.ts @@ -11,15 +11,7 @@ import { toRefs, } from 'vue-demi' import { StoreGetters, StoreState } from './store' -import type { - _ActionsTree, - _GettersTree, - _UnwrapAll, - PiniaCustomStateProperties, - StateTree, - Store, - StoreGeneric, -} from './types' +import type { PiniaCustomStateProperties, StoreGeneric } from './types' type ToComputedRefs = { [K in keyof T]: ToRef extends Ref @@ -27,31 +19,13 @@ type ToComputedRefs = { : ToRef } -/** - * Extracts the refs of a state object from a store. If the state value is a Ref or type that extends ref, it will be kept as is. - * Otherwise, it will be converted into a Ref. - * @internal - */ -type ToStateRefs = - SS extends Store< - string, - infer UnwrappedState, - _GettersTree, - _ActionsTree - > - ? UnwrappedState extends _UnwrapAll> - ? { - [K in Key]: ToRef - } - : ToRefs - : ToRefs> - /** * Extracts the return type for `storeToRefs`. * Will convert any `getters` into `ComputedRef`. */ -export type StoreToRefs = ToStateRefs & - ToRefs>> & +export type StoreToRefs = ToRefs< + StoreState & PiniaCustomStateProperties> +> & ToComputedRefs> /** diff --git a/packages/pinia/test-dts/customizations.test-d.ts b/packages/pinia/test-dts/customizations.test-d.ts index 54bd5b30..b937c989 100644 --- a/packages/pinia/test-dts/customizations.test-d.ts +++ b/packages/pinia/test-dts/customizations.test-d.ts @@ -193,76 +193,3 @@ 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) - return { - n, - customN, - double, - } - })() - ) -) - -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 } - 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++ - }, - }, - })() - ) -) -- 2.47.2