diff --git a/packages/pinia/src/types.ts b/packages/pinia/src/types.ts index d4e4089739..fcd99cb32b 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 b53749b2dc..696dca4fa9 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)