From: Eduardo San Martin Morote Date: Tue, 21 Feb 2023 07:52:29 +0000 (+0100) Subject: fix(types): mapWritableState array X-Git-Tag: pinia@2.0.32~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7ad90d319c4fad29f40622a6b95e605c47377f9;p=thirdparty%2Fvuejs%2Fpinia.git fix(types): mapWritableState array Fix #2014 --- diff --git a/packages/pinia/src/mapHelpers.ts b/packages/pinia/src/mapHelpers.ts index 6e1b5b70..33803a00 100644 --- a/packages/pinia/src/mapHelpers.ts +++ b/packages/pinia/src/mapHelpers.ts @@ -467,7 +467,12 @@ export function mapWritableState< >( useStore: StoreDefinition, keys: readonly Keys[] -): { [K in Keys]: S[K] } +): { + [K in Keys]: { + get: () => S[K] + set: (value: S[K]) => any + } +} /** * 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 974e7094..58ca9436 100644 --- a/packages/pinia/test-dts/mapHelpers.test-d.ts +++ b/packages/pinia/test-dts/mapHelpers.test-d.ts @@ -90,7 +90,12 @@ expectType<{ newToggleA: () => void }>(mapActions(useStore, { newSetToggle: 'setToggle', newToggleA: 'toggleA' })) -expectType<{ a: 'on' | 'off' }>(mapWritableState(useStore, ['a'])) +expectType<{ + a: { + get: () => 'on' | 'off' + set: (v: 'on' | 'off') => any + } +}>(mapWritableState(useStore, ['a'])) // @ts-expect-error: only defined in array mapWritableState(useStore, ['a']).b