]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(types): Don't double UnwrapRef in setup stores (#2771)
authorBartosz Gościński <bargosc@gmail.com>
Thu, 26 Sep 2024 09:29:47 +0000 (11:29 +0200)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2024 09:29:47 +0000 (11:29 +0200)
fix #2770

packages/pinia/src/types.ts
packages/pinia/test-dts/state.test-d.ts

index d4e40897393439c3ba973f52b2d57d5b07746ce0..fcd99cb32bb8e28d30ee2eed1dc028a871d03483 100644 (file)
@@ -583,7 +583,7 @@ export type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
 export type _ExtractStateFromSetupStore<SS> = SS extends undefined | void
   ? {}
   : _ExtractStateFromSetupStore_Keys<SS> extends keyof SS
-    ? _UnwrapAll<Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>>
+    ? Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>
     : never
 
 /**
index b53749b2dc1329b1c20a1bd95a3b2ef3dcebc70f..696dca4fa96b1f1b23fc8398cf89b12e949f824a 100644 (file)
@@ -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<number>(store.fromARef)
 
 expectType<{ msg: string }>(store.aShallowRef)
 expectType<{ msg: string }>(store.$state.aShallowRef)
+expectType<{ aRef: Ref<string> }>(store.anotherShallowRef)
+expectType<{ aRef: Ref<string> }>(store.$state.anotherShallowRef)
 
 const onlyState = defineStore({
   id: 'main',
@@ -83,3 +86,11 @@ onlyState.$patch((state) => {
   expectType<string>(state.some)
   expectType<string>(state.name)
 })
+
+const useSetupStore = defineStore('composition', () => ({
+  anotherShallowRef: shallowRef({ aRef: ref('hello') }),
+}))
+
+const setupStore = useSetupStore()
+expectType<{ aRef: Ref<string> }>(setupStore.anotherShallowRef)
+expectType<{ aRef: Ref<string> }>(setupStore.$state.anotherShallowRef)