Skip to content

Commit

Permalink
fix(types): mapWritableState array
Browse files Browse the repository at this point in the history
Fix #2014
  • Loading branch information
posva committed Feb 21, 2023
1 parent e48bab4 commit a7ad90d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/pinia/src/mapHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ export function mapWritableState<
>(
useStore: StoreDefinition<Id, S, G, A>,
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
Expand Down
7 changes: 6 additions & 1 deletion packages/pinia/test-dts/mapHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a7ad90d

Please sign in to comment.