From: Bartosz Gościński Date: Thu, 26 Sep 2024 09:29:47 +0000 (+0200) Subject: fix(types): Don't double UnwrapRef in setup stores (#2771) X-Git-Tag: @pinia/nuxt@0.5.5~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ad17654de4153b6f26b45b20029ca9ac4885f8d;p=thirdparty%2Fvuejs%2Fpinia.git fix(types): Don't double UnwrapRef in setup stores (#2771) fix #2770 --- diff --git a/packages/pinia/src/types.ts b/packages/pinia/src/types.ts index d4e40897..fcd99cb3 100644 --- a/packages/pinia/src/types.ts +++ b/packages/pinia/src/types.ts @@ -583,7 +583,7 @@ export type _UnwrapAll = { [K in keyof SS]: UnwrapRef } export type _ExtractStateFromSetupStore = SS extends undefined | void ? {} : _ExtractStateFromSetupStore_Keys extends keyof SS - ? _UnwrapAll>> + ? Pick> : never /** diff --git a/packages/pinia/test-dts/state.test-d.ts b/packages/pinia/test-dts/state.test-d.ts index b53749b2..696dca4f 100644 --- a/packages/pinia/test-dts/state.test-d.ts +++ b/packages/pinia/test-dts/state.test-d.ts @@ -1,4 +1,4 @@ -import { computed, ref, shallowRef } from 'vue' +import { computed, Ref, ref, shallowRef } from 'vue' import { defineStore, expectType } from './' const name = ref('Eduardo') @@ -19,6 +19,7 @@ const useStore = defineStore({ counter, aRef: ref(0), aShallowRef: shallowRef({ msg: 'hi' }), + anotherShallowRef: shallowRef({ aRef: ref('hello') }), }), getters: { @@ -67,6 +68,8 @@ expectType(store.fromARef) expectType<{ msg: string }>(store.aShallowRef) expectType<{ msg: string }>(store.$state.aShallowRef) +expectType<{ aRef: Ref }>(store.anotherShallowRef) +expectType<{ aRef: Ref }>(store.$state.anotherShallowRef) const onlyState = defineStore({ id: 'main', @@ -83,3 +86,11 @@ onlyState.$patch((state) => { expectType(state.some) expectType(state.name) }) + +const useSetupStore = defineStore('composition', () => ({ + anotherShallowRef: shallowRef({ aRef: ref('hello') }), +})) + +const setupStore = useSetupStore() +expectType<{ aRef: Ref }>(setupStore.anotherShallowRef) +expectType<{ aRef: Ref }>(setupStore.$state.anotherShallowRef)