diff --git a/packages/pinia/src/mapHelpers.ts b/packages/pinia/src/mapHelpers.ts index 742e26f963..6e1b5b704b 100644 --- a/packages/pinia/src/mapHelpers.ts +++ b/packages/pinia/src/mapHelpers.ts @@ -462,11 +462,12 @@ export function mapWritableState< Id extends string, S extends StateTree, G extends _GettersTree, - A + A, + Keys extends keyof S >( useStore: StoreDefinition, - keys: Array -): _MapWritableStateReturn + 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 diff --git a/packages/pinia/test-dts/mapHelpers.test-d.ts b/packages/pinia/test-dts/mapHelpers.test-d.ts index 991991fd1a..974e709459 100644 --- a/packages/pinia/test-dts/mapHelpers.test-d.ts +++ b/packages/pinia/test-dts/mapHelpers.test-d.ts @@ -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: {