Skip to content

Commit 4733f49

Browse files
feat(types): support IDE features for store context (#924)
1 parent b7b2c79 commit 4733f49

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

packages/pinia/src/types.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,34 +543,58 @@ export type _GettersTree<S extends StateTree> = Record<
543543
*/
544544
export type _ActionsTree = Record<string, _Method>
545545

546+
/**
547+
* @internal
548+
*/
549+
type _ExtractStateFromSetupStore_Keys<SS> = keyof {
550+
[K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any
551+
}
552+
553+
/**
554+
* @internal
555+
*/
556+
type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
557+
[K in keyof SS as SS[K] extends _Method ? K : never]: any
558+
}
559+
560+
/**
561+
* @internal
562+
*/
563+
type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
564+
[K in keyof SS as SS[K] extends ComputedRef ? K : never]: any
565+
}
566+
567+
/**
568+
* @internal
569+
*/
570+
type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
571+
546572
/**
547573
* @internal
548574
*/
549575
export type _ExtractStateFromSetupStore<SS> = SS extends undefined | void
550576
? {}
551-
: {
552-
[K in keyof SS as SS[K] extends _Method | ComputedRef
553-
? never
554-
: K]: UnwrapRef<SS[K]>
555-
}
577+
: _ExtractStateFromSetupStore_Keys<SS> extends keyof SS
578+
? _UnwrapAll<Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>>
579+
: never
556580

557581
/**
558582
* @internal
559583
*/
560584
export type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void
561585
? {}
562-
: {
563-
[K in keyof SS as SS[K] extends _Method ? K : never]: SS[K]
564-
}
586+
: _ExtractActionsFromSetupStore_Keys<SS> extends keyof SS
587+
? Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>
588+
: never
565589

566590
/**
567591
* @internal
568592
*/
569593
export type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void
570594
? {}
571-
: {
572-
[K in keyof SS as SS[K] extends ComputedRef ? K : never]: UnwrapRef<SS[K]>
573-
}
595+
: _ExtractGettersFromSetupStore_Keys<SS> extends keyof SS
596+
? _UnwrapAll<Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>>
597+
: never
574598

575599
/**
576600
* Options passed to `defineStore()` that are common between option and setup

0 commit comments

Comments
 (0)