Skip to content

Commit 647373e

Browse files
committed
refactor: export internal types
1 parent 4733f49 commit 647373e

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

packages/pinia/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type {
2727
_StoreWithState,
2828
StoreProperties,
2929
StoreOnActionListener,
30+
_StoreOnActionListenerContext,
3031
StoreOnActionListenerContext,
3132
SubscriptionCallback,
3233
SubscriptionCallbackMutation,
@@ -40,6 +41,14 @@ export type {
4041
DefineStoreOptions,
4142
DefineSetupStoreOptions,
4243
DefineStoreOptionsInPlugin,
44+
_ExtractActionsFromSetupStore,
45+
_ExtractGettersFromSetupStore,
46+
_ExtractStateFromSetupStore,
47+
_DeepPartial,
48+
_ExtractActionsFromSetupStore_Keys,
49+
_ExtractGettersFromSetupStore_Keys,
50+
_ExtractStateFromSetupStore_Keys,
51+
_UnwrapAll,
4352
} from './types'
4453
export { MutationType } from './types'
4554

packages/pinia/src/store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import {
2727
StateTree,
2828
SubscriptionCallback,
29-
DeepPartial,
29+
_DeepPartial,
3030
isPlainObject,
3131
Store,
3232
_Method,
@@ -55,7 +55,7 @@ type _ArrayType<AT> = AT extends Array<infer T> ? T : never
5555

5656
function mergeReactiveObjects<T extends StateTree>(
5757
target: T,
58-
patchToApply: DeepPartial<T>
58+
patchToApply: _DeepPartial<T>
5959
): T {
6060
// no need to go through symbols because they cannot be serialized anyway
6161
for (const key in patchToApply) {
@@ -250,10 +250,10 @@ function createSetupStore<
250250
const hotState = ref({} as S)
251251

252252
function $patch(stateMutation: (state: UnwrapRef<S>) => void): void
253-
function $patch(partialState: DeepPartial<UnwrapRef<S>>): void
253+
function $patch(partialState: _DeepPartial<UnwrapRef<S>>): void
254254
function $patch(
255255
partialStateOrMutator:
256-
| DeepPartial<UnwrapRef<S>>
256+
| _DeepPartial<UnwrapRef<S>>
257257
| ((state: UnwrapRef<S>) => void)
258258
): void {
259259
let subscriptionMutation: SubscriptionCallbackMutation<S>

packages/pinia/src/types.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function isPlainObject(
3232
*
3333
* @internal
3434
*/
35-
export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> }
35+
export type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> }
3636
// type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
3737

3838
// TODO: can we change these to numbers?
@@ -112,7 +112,7 @@ export interface SubscriptionCallbackMutationPatchObject<S>
112112
/**
113113
* Object passed to `store.$patch()`.
114114
*/
115-
payload: DeepPartial<S>
115+
payload: _DeepPartial<S>
116116
}
117117

118118
/**
@@ -142,8 +142,6 @@ export type SubscriptionCallbackMutation<S> =
142142
| SubscriptionCallbackMutationPatchObject<S>
143143
| SubscriptionCallbackMutationPatchFunction
144144

145-
export type UnwrapPromise<T> = T extends Promise<infer V> ? V : T
146-
147145
/**
148146
* Callback of a subscription
149147
*/
@@ -164,8 +162,13 @@ export type SubscriptionCallback<S> = (
164162
/**
165163
* Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring
166164
* purposes. For internal use only.
165+
* @internal
167166
*/
168-
interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
167+
export interface _StoreOnActionListenerContext<
168+
Store,
169+
ActionName extends string,
170+
A
171+
> {
169172
/**
170173
* Name of the action
171174
*/
@@ -191,12 +194,12 @@ interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
191194
after: (
192195
callback: A extends Record<ActionName, _Method>
193196
? (
194-
resolvedReturn: UnwrapPromise<ReturnType<A[ActionName]>>
197+
resolvedReturn: Awaited<ReturnType<A[ActionName]>>
195198
// allow the after callback to override the return value
196199
) =>
197200
| void
198201
| ReturnType<A[ActionName]>
199-
| UnwrapPromise<ReturnType<A[ActionName]>>
202+
| Awaited<ReturnType<A[ActionName]>>
200203
: () => void
201204
) => void
202205

@@ -328,7 +331,7 @@ export interface _StoreWithState<
328331
*
329332
* @param partialState - patch to apply to the state
330333
*/
331-
$patch(partialState: DeepPartial<UnwrapRef<S>>): void
334+
$patch(partialState: _DeepPartial<UnwrapRef<S>>): void
332335

333336
/**
334337
* Group multiple changes into one function. Useful when mutating objects like
@@ -544,30 +547,34 @@ export type _GettersTree<S extends StateTree> = Record<
544547
export type _ActionsTree = Record<string, _Method>
545548

546549
/**
550+
* Type that enables refactoring through IDE.
547551
* @internal
548552
*/
549-
type _ExtractStateFromSetupStore_Keys<SS> = keyof {
553+
export type _ExtractStateFromSetupStore_Keys<SS> = keyof {
550554
[K in keyof SS as SS[K] extends _Method | ComputedRef ? never : K]: any
551555
}
552556

553557
/**
558+
* Type that enables refactoring through IDE.
554559
* @internal
555560
*/
556-
type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
561+
export type _ExtractActionsFromSetupStore_Keys<SS> = keyof {
557562
[K in keyof SS as SS[K] extends _Method ? K : never]: any
558563
}
559564

560565
/**
566+
* Type that enables refactoring through IDE.
561567
* @internal
562568
*/
563-
type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
569+
export type _ExtractGettersFromSetupStore_Keys<SS> = keyof {
564570
[K in keyof SS as SS[K] extends ComputedRef ? K : never]: any
565571
}
566572

567573
/**
574+
* Type that enables refactoring through IDE.
568575
* @internal
569576
*/
570-
type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
577+
export type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
571578

572579
/**
573580
* @internal

0 commit comments

Comments
 (0)