]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(types): mapWritableState array
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 20 Feb 2023 09:08:41 +0000 (10:08 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 20 Feb 2023 09:08:41 +0000 (10:08 +0100)
Fix #2014

packages/pinia/src/mapHelpers.ts
packages/pinia/test-dts/mapHelpers.test-d.ts

index 742e26f96370992a8f927858bb436209677a154a..6e1b5b704b3d59ddbc74a1e699b2e17b9a3af963 100644 (file)
@@ -462,11 +462,12 @@ export function mapWritableState<
   Id extends string,
   S extends StateTree,
   G extends _GettersTree<S>,
-  A
+  A,
+  Keys extends keyof S
 >(
   useStore: StoreDefinition<Id, S, G, A>,
-  keys: Array<keyof S>
-): _MapWritableStateReturn<S>
+  keys: readonly Keys[]
+): { [K in Keys]: S[K] }
 /**
  * Allows using state and getters from one store without using the composition
  * API (`setup()`) by generating an object to be spread in the `computed` field
index 991991fd1a299e9820420eefbab92d40b259eaf2..974e709459252a5b4e4d172e5ddc4984dc6ef13e 100644 (file)
@@ -90,12 +90,9 @@ expectType<{
   newToggleA: () => void
 }>(mapActions(useStore, { newSetToggle: 'setToggle', newToggleA: 'toggleA' }))
 
-expectType<{
-  a: {
-    get: () => 'on' | 'off'
-    set: (v: 'on' | 'off') => any
-  }
-}>(mapWritableState(useStore, ['a']))
+expectType<{ a: 'on' | 'off' }>(mapWritableState(useStore, ['a']))
+// @ts-expect-error: only defined in array
+mapWritableState(useStore, ['a']).b
 
 expectType<{
   newA: {