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 20, 2023
1 parent 4674900 commit 07eaf99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 4 additions & 3 deletions packages/pinia/src/mapHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions packages/pinia/test-dts/mapHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 07eaf99

Please sign in to comment.